0

I load image from url. it' ok, but when long time it error outofmemory: bitmap size exceeds vm budget. here my code

    BitmapFactory.Options bmOptions;
    bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    //from web
    try {
        Bitmap bitmap=null;
        InputStream is=new URL(url).openStream();
        BitmapFactory.decodeStream(is, null, bmOptions);
        is.close();
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = 1;
        is = new URL(url).openStream();
        bitmap = BitmapFactory.decodeStream(is, null, o2);
        is.close();
        return bitmap;
    } catch (Exception ex){
       ex.printStackTrace();
       return null;
    }

help me please!!

Bad Badtz
  • 25
  • 1
  • 6

4 Answers4

2

Try using the sampleSize of BitmapFactory.Options, this will reduce the size in memory of your image (and the quality)

But if your image is really too big, I think that's there no miracle solution, the image is simply too big ...

Jokahero
  • 1,074
  • 10
  • 21
  • i use simpleSize image to tiny cause image it large – Bad Badtz Jun 03 '11 at 07:53
  • Uh sorry I missed it ^^'. But I think that a value of 1 doesn't change anything, "If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory." (from Android reference) – Jokahero Jun 03 '11 at 07:56
  • my app load image from url to show pic that image is large. In listview i use simplesize but in imageview if i use ismplesize > 1, that image to smaller. – Bad Badtz Jun 03 '11 at 08:08
  • So I think there's nothing to do :/ As I said there's no miracle solution. – Jokahero Jun 03 '11 at 08:12
1

Your problem is exactly what stated in error message: your image is too big to be loaded into memory.

inazaruk
  • 74,247
  • 24
  • 188
  • 156
0

Try with any other image. As this image is exceding the size of ur folder.

R u using Emulator to test it?

Stuti
  • 1,620
  • 1
  • 16
  • 33
0

Just a idea, it could be this piece of code throws sometime a exception. This will causes that the InputStream will not release rthe asigned resources (memory leak).

if you close the Input stream in a finaly block this issue should be solved

Mark Bakker
  • 1,278
  • 8
  • 19