Skip to content Skip to sidebar Skip to footer

Java.lang.outofmemoryerror Bitmap Size Exceeds Vm Budget On Bitmap

In my app I'm displaying images from galley and on selection of image i want to upload that image to web server.For uploading image to server I'm using following code but I'm getti

Solution 1:

Error is due to the size of the image, i used this code to decrease the size of image when select from gallery.

public Bitmap setImageToImageView(String filePath) 
    { 
    // Decode image size 
    BitmapFactory.Optionso=newBitmapFactory.Options(); 
    o.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(filePath, o); 

    // The new size we want to scale to finalintREQUIRED_SIZE=1024; 

    // Find the correct scale value. It should be the power of 2. intwidth_tmp= o.outWidth, height_tmp = o.outHeight; 
    intscale=1; 
    while (true) 
    { 
    if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) 
    break; 
    width_tmp /= 2; 
    height_tmp /= 2; 
    scale *= 2; 
    } 

    // Decode with inSampleSize 
    BitmapFactory.Optionso2=newBitmapFactory.Options(); 
    o2.inSampleSize = scale; 
    Bitmapbitmap= BitmapFactory.decodeFile(filePath, o2); 
    return bitmap;

    }

i hope this may helps you.

Solution 2:

You have to break in to samples while loading the image, there is already a question and a good answer for it, have a look at this page , this might help you.

Strange out of memory issue while loading an image to a Bitmap object

Post a Comment for "Java.lang.outofmemoryerror Bitmap Size Exceeds Vm Budget On Bitmap"