I am trying to download an 1mb image file and then save to bitmap to populate an imageview. but shows error
06-13 13:39:48.149: ERROR/AndroidRuntime(1782):
java.lang.OutOfMemoryError: bit开发者_C百科map size exceeds VM budget
How can I download a large image?
I had been through the same issue. Before you set the downloaded bitmap to your ImageView
, you have to compress your bitmap according to the width and height of your ImageView
.
You have to create a scaled bitmap like this,
bm1=Bitmap.createScaledBitmap(bm, 300, 300,true);
imgView.setImageBitmap(bm1);
or Compress your bitmap like this,
OutputStream fOut = null;
File file = new File(strDirectoy,imgname);
fOut = new FileOutputStream(file);
bm1.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
精彩评论