打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android Out of memory (many bitmaps)

Its a known bug, its not because of large files.

Bitmap is stored in native heap, but it will get garbage collected automatically, calling recycle() or by other process by making weakreference or softreference To fix OutOfMemory you should do something like this:

options.inSampleSize = calculateInSampleSize(options,bitmapWidth,bitmapHeight);public static int calculateInSampleSize(        BitmapFactory.Options options, int reqWidth, int reqHeight) {final int height = options.outHeight;final int width = options.outWidth;int inSampleSize = 1;if (height > reqHeight || width > reqWidth) {    final int halfHeight = height / 2;    final int halfWidth = width / 2;    // Calculate the largest inSampleSize value that is a power of 2 and keeps both    // height and width larger than the requested height and width.    while ((halfHeight / inSampleSize) > reqHeight            && (halfWidth / inSampleSize) > reqWidth) {        inSampleSize *= 2;    }}    return inSampleSize;}

For example, an image with resolution 2048x1536 that is decoded with an inSampleSize of 4 produces a bitmap of approximately 512x384

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android Bitmap 全面解析(一) 加载大尺寸图片
浅析KJFrameForAndroid框架如何高效加载Bitmap
Android图片缩放总结及比较
Android客户端性能优化(魅族资深工程师毫无保留奉献)
android BitmapFactory的OutOfMemoryError: bitma...
java.lang.OutOfMemoryError:?bitmap?size?excee...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服