📄 impsquarescaletransform.cs
字号:
namespace Imps.Utils
{
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
public sealed class ImpSquareScaleTransform : ImpScaleTransform
{
public ImpSquareScaleTransform(int w) : base(w, w, true)
{
}
public override IImage Transform(IImage image)
{
IImage image5;
if (image == null)
{
throw new ArgumentNullException("image");
}
int width = base.Width;
int height = base.Height;
int x = 0;
int y = 0;
IImage image2 = null;
try
{
image2 = (IImage) image.Clone();
using (Image image3 = image.Image)
{
using (Image image4 = new Bitmap(base.Width, base.Height, image3.PixelFormat))
{
using (Graphics graphics = Graphics.FromImage(image4))
{
float num5 = image.Width;
float num6 = image.Height;
float num7 = 0f;
float num8 = 0f;
if (num5 > num6)
{
num7 = (num5 - num6) / 2f;
num5 = num6;
}
else if (num6 > num5)
{
num8 = (num6 - num5) / 2f;
num6 = num5;
}
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawImage(image3, new Rectangle(x, y, width, height), new Rectangle(Convert.ToInt32(num7), Convert.ToInt32(num8), Convert.ToInt32(num5), Convert.ToInt32(num6)), GraphicsUnit.Pixel);
}
image2.Image = image4;
}
}
image5 = image2;
}
catch (Exception exception)
{
if (image2 != null)
{
image2.Dispose();
}
throw exception;
}
return image5;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -