Android的可绘制VS资产在图像加载性能 [英] Android Drawable vs Asset in Image loading performance

查看:159
本文介绍了Android的可绘制VS资产在图像加载性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是来自韩国的Andr​​oid开发者

I'm android developer from Korea

我的项目大约有装载大量巨大的位图的功能(约2,000×1,500px)

My project has features about loading large amount of huge bitmap (about 2,000 x 1,500px)

我有一些实验来比较时资产和绘制对象之间的复杂度和空间复杂度

I had a some experiments to compare time complexity and space complexity between Asset and Drawable

这是结果,资产比空间复杂度绘好。

By result, Asset is better than drawable in space complexity.

当我加载使用可绘制的图像巨大,我的应用程序分解与OutOfMemoryException异常:位图大小超过VM预算

When I load huge images using drawable, my app broken down with OutOfMemoryException : the bitmap size exceeds VM budget

但是当我加载使用资产庞大的图像,它工作正常!

but when I load huge images using Asset, It works fine!

有人知道为什么发生这种情况?

Anybody know reason why this happened?

或任何人都知道如何绘制对象工作在Android框架?一步步。

or Anybody know about how Drawable works in Android framework? step-by-step.

请帮忙。

感谢您的阅读。

推荐答案

如果您传递的资产乌里来像一个的ImageView ,该框架将使用 BitmapFactory 从磁盘流图像的下采样版本。 是它使用引擎盖下的技术。

If you are passing an asset Uri to something like an ImageView, the framework will use BitmapFactory to stream a downsampled version of the image from disk. This is the technique it uses under the hood.

可绘制■不要使用这种技术,性能方面的原因。这不是普遍预期,巨大的影像被保存为可绘制 s和可绘制加载在你的应用程序的生命周期中会发生很多次,所以他们在整体磁盘流并缓存在内存中。

Drawables do not use this technique, for performance reasons. It is not generally expected that huge images are stored as Drawables, and Drawable loading happens many times over your app's lifecycle, so they are streamed from disk in their entirety and cached in memory.

这篇关于Android的可绘制VS资产在图像加载性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆