简体   繁体   English

Android:如何使用Fresco旋转图像

[英]Android: how to rotate image using Fresco

I am using Fresco to load images from phone storage by uri into SimpleDraweeView (both internal and external, using content provider - 'content://'). 我正在使用Fresco通过uri将来自手机存储的图像加载到SimpleDraweeView(内部和外部,都使用内容提供程序-'content://')。 They are loading fine, but keep rotating if they have orientation set in their properties. 它们的负载很好,但是如果在属性中设置了方向,则继续旋转。 I tried to set imageRequest with .setAutoRotateEnabled(true) property, but for some reason it doesn't work for me. 我尝试使用.setAutoRotateEnabled(true)属性设置imageRequest,但是由于某些原因,它对我不起作用。 Any suggestions on how to rotate images to display them properly? 关于如何旋转图像以正确显示它们有什么建议吗?

imageView.setController(
            controllerBuilder
                    .setOldController(imageView.getController())
                    .setImageRequest(imageRequestBuilder
                            .setSource(uri)
                            .setAutoRotateEnabled(true)
                            .setResizeOptions(null)
                            .build())
                    .build());

I had this issue solved by setting .setDownsampleEnabled(false). 我通过设置.setDownsampleEnabled(false)解决了这个问题。 I don't know why, but I guess that downsampling is REALLY experimantal yet and prevents auto-rotating to happen. 我不知道为什么,但是我想降采样确实是实验性的,可以防止自动旋转的发生。

Auto-rotate is the default, so the image will rotate if the orientation is set. 默认设置为“自动旋转”,因此如果设置了方向,图像将旋转。 Try setting it to false if that's not what you want. 如果这不是您想要的,请尝试将其设置为false。

I also had the same issue, where having downsampling enabled in Fresco prevents you from being able to disable auto-rotation of images with EXIF data. 我也遇到了同样的问题,在Fresco中启用了下采样功能使您无法禁用具有EXIF数据的图像的自动旋转。

I recently opened an issue about this, and the fact that auto-rotation is on by default but this is not documented anywhere, which caused me hours of head-scratching. 我最近打开了一个与此有关的问题 ,该问题默认情况下为自动旋转,但是任何地方都没有记录,这使我费时费力。 No response from Fresco devs as yet. 尚未收到Fresco开发人员的回应。

EDIT: The issue is now fixed in Fresco v0.14. 编辑:该问题现在已在Fresco v0.14中修复。

For some reason setAutoRotateEnabled(true) also didn't work for me so I forced to always rotate to 90 degrees 由于某些原因, setAutoRotateEnabled(true)也对我不起作用,因此我不得不始终旋转到90度

Kotlin code Kotlin代码

       val request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setResizeOptions(ResizeOptions(width, height))
            .setRotationOptions(RotationOptions.forceRotation(RotationOptions.ROTATE_90))
            .build()

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

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