Reputation: 3
I'm stuck with this issue since 2 days : I want to compress a bitmap (JPEG).
I found some useful information here and on Google but none work fine.
My JPEG file is in the assets. I can read it without problem, retrieve all the info. When I compress it, my byte[] array is fine, but with decodeByteArray, the size is the same as original.
Here the Code
InputStream in = assets.open(fileName);
Config config = Bitmap.Config.RGB_565;
Options options = new Options();
options.inPreferredConfig = config;
Bitmap bitmap = BitmapFactory.decodeStream(in, null, options);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, out);
bitmap = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()),null,options);
I don't know what to do. Thank you in advance for your time
Upvotes: 0
Views: 142
Reputation: 740
Look the documentation here.. It can help You with other tips, like reduce the dimension of the image..
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Upvotes: 0
Reputation: 20520
Decoding does the reverse of the compression: it turns it into raw pixel data. Compression is useful for reducing the file size for storage and transmission, but when the image gets displayed, it gets decompressed in memory to the same size it was when it started.
If you want to make the raw pixel data smaller, you need to reduce the resolution. The ImgScalr library will help you here: it produces very good results.
(But I'm not exactly sure what it is you're trying to achieve.)
Upvotes: 1