我知道这个问题早先得到了回答,但不知怎的,我无法从可用的解决方案中解决问题。
using (var stream = new FileStream(@"D:\test\6.png", FileMode.Open))
{
var path = @"D:\test1\";
using (var image = Image.FromStream(stream))
{
var newWidth = (int)(image.Width * 0.5);
var newHeight = (int)(image.Height * 0.5);
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(path, image.RawFormat);
}
}
当我运行以下代码时,我收到错误
未处理的类型' System.Runtime.InteropServices.ExternalException'发生在System.Drawing.dll
中其他信息:GDI +中发生了一般性错误。
答案 0 :(得分:0)
路径变量不指向实际文件名而只指向文件夹名称。那是你的问题。 :)
如果您将其更改为
var path = @"D:\test1\newImage.bmp";
或类似它应该工作。 (将扩展名更改为与输出图像格式匹配的内容)