Android Bitmap那些事之如何优化内存

上一步你已经获取到图片的原始尺寸了,下一步就是要把原图缩放到你需要的大小,可以通过inSampleSize参数来设置,google原文的解释是:If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value <= 1 is treated the same as 1. Note: the decoder will try to fulfill this request, but the resulting bitmap may have different dimensions that precisely what has been requested. Also, powers of 2 are often faster/easier for the decoder to honor.(不管你看不看英文文档我还是要把google原文贴出来,我英文比较烂,翻译的不一定准确),大概意思就是说这个参数可以调节你在decode原图时所需要的内存,有点像采样率,会丢掉一些像素,值是大于1的数,为2的幂时更利于运算。举个例子:当inSampleSize == 4时会返回一个尺寸(长和宽)是原始尺寸1/4,,像素是原来1/16的图片。这个值怎么计算呢?

你的脸是为了呈现上帝赐给人类最贵重的礼物–微笑,

Android Bitmap那些事之如何优化内存

相关文章:

你感兴趣的文章:

标签云: