google了一下,找到了這篇[C#] 影像檔大小縮放,發現它完全達到跟我所需要的功能
所以拿了這兩個Function來用
程式碼:
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;
}
資料來源:愛流浪的小風-[C#] 影像檔大小縮放
沒有留言:
張貼留言