如何在ImageResizer中使用autorotate插件

Mar*_*les 5 c# autorotate imageresizer

如何在ac#console应用程序中使用AutoRotate插件?我以为我能做的事情就像settings.AutoRotate = true;我可以改变合身模式来使用接缝雕刻插件.

我已经尝试settings.Add("autorotate","true")过keycollection,以及其他键名AutoRotateautoRotate.

我在一个简单的方法中使用它.

    new AutoRotate().Install(ImageResizer.Configuration.Config.Current);
    ...
    protected static Image ResizeImage(Image image, double scaleFactor)
    {
        var settings = new ResizeSettings
        {
            Scale = ScaleMode.Both,
            Width = (int)Math.Floor(Image.Width * scaleFactor),
            Height = (int)Math.Floor(Image.Height * scaleFactor),
            Mode = FitMode.None,
            Format = "png"
        };

        settings.Set("autorotate", "true");
        return ImageBuilder.Current.Build(image, settings, true);
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*les 5

经过大量的研究,我发现了我正在制作的错误,并揭示了.Net的一个不错的"隐藏功能"!

当图像被读入Bitmap对象时,元数据被擦除,因此,通过接受Image对象,有关方向的数据将丢失,并且自动旋转不会启动.因此,传递图像文件名而不是图像对象,我上面的代码工作!

多谢你们!

  • 如果传入图像对象是错误的,那么为什么要允许呢? (3认同)
  • **始终让ImageResizer处理文件名或Streams.如果传递图像/位图(in-out-out),则会绕过重要的图像编码/解码工作,并可能引入内存泄漏.** (2认同)