Android:替代 GIF 加载器?
我想在 Android 中加载图像,但如果图像太大,我想在加载之前调整其大小。我了解到,可以使用 BitmapFactory 来获取图像的大小,然后可以找出适当的缩放因子并使用 BitmapFactory 加载具有所需尺寸的图像(根据我发现的非常有能力的建议 在此相关线程中)。
所以我尝试了一下,但它不起作用。我花了最后一个小时浏览代码,试图找出为什么这样一个简单的操作没有任何效果(比例因子被完全忽略了!)
然后我偶然发现了 Android 问题 3072...事实证明,该问题已被认定为 GIF 文件损坏两年多了。我意识到 GIF 并不完全是现代的,但它仍然存在并被广泛使用(我的测试集有很多 GIF,这就是为什么在我发现那个错误报告之前它似乎都被破坏了)。
我的问题是,我可以使用什么来替代 BitmapFactory,以便在使用缩放因子时正确读取 GIF 文件并调整其大小,而不会默默地忽略它? 内存限制妨碍直接加载大图像以进行进一步处理,所以这需要是一个流解决方案。
我的另一个问题是,有多少其他人遇到了这样的旧的、未修复的错误,要么没有意识到,要么更糟糕的是,依赖 API 来准确执行请求的功能,最终导致内存泄漏和其他奇怪的意外?
I want to load images in Android, but if the image is just too large I wanted to resize it prior to loading . I learned that one can use the BitmapFactory to get just the size of the image, then one can figure out an appropriate scaling factor and use BitmapFactory to load the image with the required dimensions (per the very competent suggestions I found in this related thread).
So I tried that and it refused to work. I spent the last hour picking through the code trying to figure out why such a simple operation wasn't having any effect whatsoever (the scaling factor was being utterly ignored!)
Then I stumbled upon Android issue 3072... turns out this has been identified as broken for GIF files for well over two years. I realize GIF isn't exactly modern but it's still out there and in wide use (my test set has a lot of them, which is why it seemed uniformly broken until I found that bug report).
My question is, what can I use as an alternative to BitmapFactory that will correctly read and resize a GIF file when a scaling factor is employed without silently ignoring it? Memory constraints preclude loading large images directly for further processing, so this would need to be a streaming solution.
My other question is, how many others run into old, unfixed bugs like this and either don't realize it or worse, rely on the API to accurately perform the requested function and end up with memory leaks and other strange surprises?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用了此处发布的解决方案。
其中
scaleDown
是:如此处所使用。
I ended up using the solution posted here.
Where
scaleDown
is:as used here.