[ C# ] 影像檔大小縮放
public class ImageResize
{
public static Bitmap Resize(Bitmap originImage, Double times)
{
int width = Convert.ToInt32(originImage.Width * times);
int height = Convert.ToInt32(originImage.Height * times);
return Process(originImage,originImage.Width,originImage.Height,width,height);
}
private static Bitmap Process(Bitmap originImage, int oriwidth, int oriheight,int width,int height)
{
Bitmap resizedbitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(resizedbitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(Color.Transparent);
g.DrawImage(originImage, new Rectangle(0, 0, width, height), new Rectangle(0, 0, oriwidth, oriheight), GraphicsUnit.Pixel);
return resizedbitmap;
}
}