C# gdi+;从控制台应用程序保存映像时出错

C# gdi+;从控制台应用程序保存映像时出错,c#,asp.net,image-processing,gdi,C#,Asp.net,Image Processing,Gdi,我知道这个问题早些时候已经得到了回答,但不知何故,我无法从现有的解决方案中解决这个问题 using (var stream = new FileStream(@"D:\test\6.png", FileMode.Open)) { var path = @"D:\test1\"; using (var image = Image.FromStream(stream))

我知道这个问题早些时候已经得到了回答,但不知何故,我无法从现有的解决方案中解决这个问题

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.Drawing.dll中发生“System.Runtime.InteropServices.ExternalException”类型的未处理异常


其他信息:GDI+中发生一般错误

path变量不指向实际文件名,只指向文件夹名。这就是你的问题。:)

如果你把它改成

 var path = @"D:\test1\newImage.bmp";

或者类似的,它应该会起作用。(将扩展名更改为与输出图像格式匹配的内容)

您的“path”变量设置为什么?以防万一,它试图覆盖文件流当前正在使用的相同图像。另外,我希望newWidth和newHeight大于0:-)最后一件事:确保input 6.png没有以任何方式损坏。我已经为path变量编辑了我的帖子。newWidth和newHeight都大于零。