优化使用BitmapFactory.Options.inSampleSize的速度速度、BitmapFactory、Options、inSampleSize

由网友(半生輕狂客)分享简介:由于 Schermvlieger 的作为询问this对问题的 anddev.org 我只是模仿他的问题等其他网站因为没有人回答,我也面临着同样的问题。我想知道什么将是最佳使用 BitmapFactory.Options.inSampleSize 的问候显示图像的速度。该文件提到使用是2的功率值,所以我用2,4,8...

由于 Schermvlieger 的作为询问this对问题的 anddev.org

我只是模仿他的问题等其他网站因为没有人回答,我也面临着同样的问题。

我想知道什么将是最佳使用 BitmapFactory.Options.inSampleSize 的问候显示图像的速度。 该文件提到使用是2的功率值,所以我用2,4,8,16等。

工作

的事情,我想知道的都是:

我应该重新取样下来到仍比屏幕分辨率大尺寸最小,或者我应该品尝到的大小刚好够避免的OutOfMemoryError ? 如何能计算的图像,可能仍然不会耗尽内存中显示的最大尺寸是多少?是否颜色深度的图像的发挥作用,以及,在显示屏的深度α 是否有效地通过两个机制( BitmapFactory 对于大文件, setImageURI()为较小的显示图像)我使用的是 ImageSwitcher 的方式。 它是否有助于创建位图 BitmapFactory.Options inTempStorage 在应用程序的开头或仅在飞,在需要的时候? 解决方案

您应该总是尝试加载和pre级图像,使他们尽可能接近它们的最终显示的大小。在绘图时缩放图像是非常昂贵的,应该避免不惜一切代价。

考虑到图像的存储成本,是的,颜色deptch起着非常重要的作用。在每个像素ALPHA_8格式使用1个字节的图像,在RGB_565或ARGB_4444图像,请使用每个像素和图像2字节ARGB_8888使用每个像素的4个字节。显示器的深度没有关系的。你应该总是尝试使用ARGB_8888,以获得最好的质量,但是565可以足够好,如果你的形象是不透明的。

天创盛世教你如何修改网站标题

Thanks to Schermvlieger for asking this question on anddev.org,

I'm just copying his question to SO as nobody replied on the other site and I'm also facing the same problem.

I was wondering what would be the optimal use of BitmapFactory.Options.inSampleSize with regards to speed of displaying the image. The documentation mentions using values that are a power of 2, so I am working with 2, 4, 8, 16 etc.

The things I am wondering about are:

Should I resample down to the smallest size that is still larger than the screen resolution, or should I sample down to the size just enough to avoid an OutOfMemoryError? How would one calculate the maximum size of an image that could still be displayed without running out of memory? Does the color-depth of the image play a role as well, and the depth of the display? Is it efficient to display images via two mechanisms (BitmapFactory for large files, setImageURI() for smaller ones) I am using an ImageSwitcher by the way. Would it help creating the Bitmap, BitmapFactory.Options and inTempStorage in the beginning of the application or creating them only on the fly, when needed?

解决方案

You should always try to load and pre-scale images so that they are as close as possible to their final displayed size. Scaling images at drawing time is extremely expensive and should be avoided at all cost.

Considering the memory cost of an image, yes, the color-deptch plays a very important role. Images in ALPHA_8 format use 1 byte per pixel, images in RGB_565 or ARGB_4444 use 2 bytes per pixel and images in ARGB_8888 use 4 bytes per pixel. The depth of the display does not matter at all. You should always try to use ARGB_8888 to get the best possible quality, but 565 can be good enough if your image is opaque.

阅读全文

相关推荐

最新文章