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

标签 c# .net-4.0 photoshop image-resizing adobe-illustrator

我正在调整图像大小,如下所示:

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

相关文章:

plugins - Photoshop 导入和格式插件类型之间的差异

c# - 将存储库模式与 Entity Framework 结合使用时分离的实体

c# - WPF 中的快速像素绘制

c# - 如何在 C# 中获取类中字段的默认值?

.net - 如果缺少.NET 3.5 SP1,我可以直接安装4吗?

html - 如何修复页面宽度以缩小到屏幕大小?

c# - 跨线程操作在 Windows 窗体中无效

c# - 停止服务没有错误 "Service cannot be started. The handle is invalid"

c# - 无法从 Derived<Derived 2T> 转换为 BaseT<base 2T>

css - 可以对图像的不同部分应用或多或少的压缩吗?