0

I am trying to get inputstream by passing url of the image, but when i have more images requested it says out of memory and after sometimes the server restarts.

public InputStream getBitmap(String imagePath, int THUMBSIZE ){
        Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath), THUMBSIZE, THUMBSIZE);
        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
        ThumbImage.compress(CompressFormat.PNG, 0 , bos); 
        ThumbImage.recycle();
        byte[] bitmapdata = bos.toByteArray();
        InputStream bs = new ByteArrayInputStream(bitmapdata);  
        return bs;
    }

this is where i use above method, why it is giving out of memory error ?

String query_file = parameters.get("fname");
String Mime = get_mime(query_file);
String original_path = root.getAbsolutePath()+query_file;                   
InputStream br = this.getBitmap(original_path, 96);

2 Answers 2

1

Have a good look at this documetation: Documentation

This lesson walks you through decoding large bitmaps without exceeding the per application memory limit by loading a smaller subsampled version in memory.

scale your Image to the needed size and alloc your memory.

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

1 Comment

I am lazy to read second paragraph but now i got it, for those who have similar problem. The actual reason for out of memory is when we decode it we are using that big image to store in our memory instead of that you need to use options class where there is an option which should be greater than 1 to reduce the usage of memory. just read the documetation link given in the above answer
0

welcome to the error called

java.lang.OutOfMemoryError: bitmap size exceeds VM budget

that happens when you load high resolution heavy image or images from the url.

The Android Training class, "Displaying Bitmaps Efficiently" or try "Universal Image Loader", offers some great information for understanding and dealing with the exception.

2 Comments

I just want to get thumnails, can we do this without bitmaps, using some native 2d graphics api ?
Just now read that we cannot use BufferedImage class and 2d graphics api in android, so it simply says we need to use bitmaps.

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.