gpt4 book ai didi

c# - ImageProcessor 似乎在调整大小后将图像旋转 90 度

转载 作者:行者123 更新时间:2023-12-02 00:57:34 25 4
gpt4 key购买 nike

我使用 nuget for c# 下载了 ImageProcessor 库。我正在使用它来上传和调整网站图像的大小。上传过程工作正常,除了当我尝试查看上传的图像时,它看起来从原始图像向后旋转了 90 度。这是我正在使用的代码:

        ISupportedImageFormat format = new JpegFormat { Quality = 70 };

using (MemoryStream inStream = new MemoryStream(_img))
{
using (MemoryStream outStream = new MemoryStream())
{
// Initialize the ImageFactory using the overload to preserve EXIF metadata.
using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
{
// Load, resize, set the format and quality and save an image.
imageFactory.Load(inStream)
.Resize(new ResizeLayer(new Size(width, height), resizeMode: resizeMode))
.Format(format)
.Save(outStream);
}

return outStream.ToArray();
}
}

最佳答案

如果您不保留 EXIF 元数据,则 ImageFactory 类有一个方法 AutoRotate 可以改变图像以补偿原始方向。

http://imageprocessor.org/imageprocessor/imagefactory/autorotate/

您的新代码如下。

ISupportedImageFormat format = new JpegFormat { Quality = 70 };

using (MemoryStream inStream = new MemoryStream(_img))
{
using (MemoryStream outStream = new MemoryStream())
{
// Initialize the ImageFactory using the overload to preserve EXIF metadata.
using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
{
// Load, resize, set the format and quality and save an image.
imageFactory.Load(inStream)
.AutoRotate()
.Resize(new ResizeLayer(new Size(width, height), resizeMode: resizeMode))
.Format(format)
.Save(outStream);
}

return outStream.ToArray();
}
}

关于c# - ImageProcessor 似乎在调整大小后将图像旋转 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32870503/

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