现在的位置: 首页 > 综合 > 正文

java.lang.OutOfMemoryError: bitmap size exceeds VM budget

2013年08月18日 ⁄ 综合 ⁄ 共 547字 ⁄ 字号 评论关闭

public void image(int id) {

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// 获取这个图片的宽和高
bitmap = BitmapFactory.decodeResource(getResources(), id, options); // 此时返回bm为空
options.inJustDecodeBounds = false;
// 计算缩放比
int be = (int) (options.outHeight / (float) 50);
if (be <= 0)
be = 1;
options.inSampleSize = be;
// 重新读入图片,注意这次要把options.inJustDecodeBounds 设为 false哦
bitmap = BitmapFactory.decodeResource(getResources(), id, options);

int bmpWidth = bitmap.getWidth();

int bmpHeight = bitmap.getHeight();

Log.i("RG", "bmpWidth = " + bmpWidth + ", bmpHeight = " + bmpHeight);

}

抱歉!评论已关闭.