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.Options o = new BitmapFactory.Options(); 
    o.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(filePath, o); 

    // The new size we want to scale to 
    final int REQUIRED_SIZE = 1024; 

    // Find the correct scale value. It should be the power of 2. 
    int width_tmp = o.outWidth, height_tmp = o.outHeight; 
    int scale = 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.Options o2 = new BitmapFactory.Options(); 
    o2.inSampleSize = scale; 
    Bitmap bitmap = 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"