gpt4 book ai didi

c# - 无法在 Adob​​e 软件中打开 .NET 调整大小的图像

转载 作者:行者123 更新时间:2023-11-30 20:47:50 25 4
gpt4 key购买 nike

我正在按如下方式调整图像大小:

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[]));
}

虽然这一切看起来运行良好并且大部分情况下都很好,但用户表示当他们尝试在 Adob​​e 软件中打开调整大小的图像时收到错误消息。

插图错误:

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 等中正常打开图像。似乎是 Adob​​e 软件有问题。

有什么想法吗?谢谢

最佳答案

这可以简单地通过在保存时包含 ImageFormat 来解决。

image.Save("filename.jpg", ImageFormat.Jpeg)

关于c# - 无法在 Adob​​e 软件中打开 .NET 调整大小的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25446850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com