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

时间:2015-09-30 15:50:14

标签: c# asp.net-mvc-4 image-processing image-uploading imageprocessor

我使用nuget为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();
            }
        }

1 个答案:

答案 0 :(得分:2)

如果您没有保留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();
    }
}
相关问题