如果图像大小超过1024x768,我想调整图像的大小,然后保存新实例而不是原始实例,但这段代码正在保存原始实例。我该怎么修?
private static void ResizeImage(int newWidth, int newHeight, Stream OriginalImage, string targetPath)
{
using (var image = System.Drawing.Image.FromStream(OriginalImage))
{
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imageRectangle);
thumbnailImg.Save(targetPath, image.RawFormat);
}
}
我假设"拇指指甲Img";被认为是缩小的版本的";图像";。
如果是这样,请使用专门为此目的设计的位图构造函数:
Bitmap(Image, Int32, Int32)
例如:
var thumbnail = new Bitmap(image, newWidth, newHeight);