android内存溢出

android BitmapFactory的OutOfMemoryError: bitmap ...

拈花ヽ惹草 提交于 2019-12-07 14:22:23
网上有很多解决android加载bitmap内存溢出的方法,搜了一圈做下整理总结。项目里需求是拍摄多图之后上传,部分手机会内存溢出 。 常用一种解决方法:即将载入的图片缩小,这种方式以牺牲图片的质量为代价。在 BitmapFactory 中有一个内部类 BitmapFactory.Options ,其中当 options.inSampleSize 值 >1 时,根据文档: If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. (1 -> decodes full size; 2 -> decodes 1/4th size; 4 -> decode 1/16th size). Because you rarely need to show and have full size bitmap images on your phone. For manipulations smaller sizes are usually enough. options.inSampleSize是以2的指数的倒数被进行放缩 现在问题是怎么确定inSampleSize的值?每张图片的放缩大小的比例应该是不一样的