简体   繁体   English

调整大小后,ImageProcessor似乎将图像旋转了90度

[英]ImageProcessor seems to rotate image 90 degrees after resizing

I downloaded the ImageProcessor library using nuget for c#. 我使用nuget for c#下载了ImageProcessor库。 I am using it to upload and resize image for a website. 我正在使用它上传和调整网站图像的大小。 The upload process works fine except, when I try to view the uploaded image it appears backward rotated 90 from the original image. 上载过程运行正常,除了当我尝试查看上载的图像时,它看起来比原始图像向后旋转了90度。 Here is the code that I am using: 这是我正在使用的代码:

        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();
            }
        }

If you are not preserving EXIF metadata the ImageFactory class has a method AutoRotate that will alter the image to compensate for the original orientation. 如果您不保留EXIF元数据,则ImageFactory类具有AutoRotate方法,该方法将更改图像以补偿原始方向。

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

Your new code would be as follows. 您的新代码如下。

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM