我正在调整图像大小,如下所示:
private byte[] ResizeImage(System.Drawing.Image image, double scaleFactor)
{
//a holder for the result
int newWidth = (int)(image.Width * scaleFactor);
int newHeight = (int)(image.Height * scaleFactor);
Bitmap result = new Bitmap(newWidth, newHeight);
//use a graphics object to draw the resized image into the bitmap
using (Graphics graphics = Graphics.FromImage(result))
{
//set the resize quality modes to high quality
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//draw the image into the target bitmap
graphics.DrawImage(image, 0, 0, result.Width, result.Height);
}
//return the resulting bitmap
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(result, typeof(byte[]));
}
虽然一切看起来都很完美,而且大部分都很好,但用户表示,当他们尝试在 Adobe 软件中打开调整大小的图像时,他们收到了错误消息。
插画错误:
The file "MyPhoto.jpg" is in an unknown format and cannot be opened.
Photoshop 错误:
Could not complete your request because an unknown or invalid JPEG marker type is found.
正如我所说,我可以在 Windows 查看器、Picasa、GIMP 等中很好地打开图像。 似乎只是 Adobe 软件有问题。
有什么想法吗?谢谢
最佳答案
只需在保存时包含 ImageFormat
即可解决此问题。
image.Save("filename.jpg", ImageFormat.Jpeg)
关于c# - .NET 调整大小的图像无法在 Adobe 软件中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25446850/