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!!

2

4 Answers 4

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 ...

Sign up to request clarification or add additional context in comments.

4 Comments

i use simpleSize image to tiny cause image it large
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)
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.
So I think there's nothing to do :/ As I said there's no miracle solution.
1

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

Comments

0

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

R u using Emulator to test it?

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.