优化使用BitmapFactory.Options.inSampleSize的速度 [英] Optimal use of BitmapFactory.Options.inSampleSize for speed

查看:521
本文介绍了优化使用BitmapFactory.Options.inSampleSize的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 Schermvlieger 作为询问<一个href="http://www.anddev.org/multimedia-problems-f28/optimal-use-of-bitmapfactory-options-insamplesize-for-speed-t11548.html#p36685">this对问题的 anddev.org

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

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

工作

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

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

您应该总是尝试加载和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:

  1. 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?
  2. 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?
  3. 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.
  4. 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.

这篇关于优化使用BitmapFactory.Options.inSampleSize的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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