I develop application which load gallery then copied to external folder and it was successfully, but my problem now is how to reduce (compress) file image size, I want to prevent out of memory crash application, because it will be loaded in listview. Tell me how to do. Thanks
Asked
Active
Viewed 573 times
0
2 Answers
0
To handle with Bitmap, I would like to recommend to reference. Loading Large Bitmaps Efficiently
Better to read the whole section. You have to calculate your required width and height and compress bitmap. E.g. you don't need 1024x1024 resolution to show in 100x100 image size of Gallery.
You can compress like this. But for more understanding, please refer above link I mention.
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap preview_bitmap=BitmapFactory.decodeFile(file, options);
Hopefully, this answer can help you.

Thein
- 3,940
- 2
- 30
- 34
-
can you give me tutorial for reducing size, because I will use it in PDF generating. – Agoeng Liu Nov 28 '13 at 08:48
-
Explorer here http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object for more sample code. As my understood, you compress image and generate as pdf. That's what you doing, right ? I just asking because I never done pdf generating before. Correct me if I'm wrong. – Thein Nov 28 '13 at 09:13
-
yes I have displayed image in listview with your way, now I want to generate PDF from android, I want to prevent using out of memory, so I must compress my image. – Agoeng Liu Nov 28 '13 at 09:18
0
Bitmap compressImage= Bitmap.createScaledBitmap(bitmap, 50, 50, false);
it will reduce image size,but it will also reduce image quality.

Kanifnath Modak
- 172
- 1
- 8