我见过很多人尝试编写自己的图像转换技术。它通常看起来很复杂,最终使用 GDI+ 函数调用,并操纵图像的位。这让我想知道在保存图像时是否缺少 .NET 图像转换调用的简单性。这是我的代码:
Bitmap tempBmp = new Bitmap("c:\temp\img.jpg");
Bitmap bmp = new Bitmap(tempBmp, 800, 600);
bmp.Save(c:\temp\img.bmp, //extension depends on format
ImageFormat.Bmp) //These are all the ImageFormats I allow conversion to within the program. Ignore the syntax for a second ;)
ImageFormat.Gif) //or
ImageFormat.Jpeg) //or
ImageFormat.Png) //or
ImageFormat.Tiff) //or
ImageFormat.Wmf) //or
ImageFormat.Bmp)//or
);
这就是我在图像转换中所做的一切。只需设置应保存图像的位置,并将其传递给 ImageFormat 类型。我已经尽我所能对其进行了测试,但我想知道我是否在这种简单的格式转换中遗漏了任何东西,或者这是否足够?