I am developing an app which generate .png images from a 1080p video. But the pngs are in MBs, and even my app is crashing due to large size of pngs. I want to compress or something like that to reduce the size of each png. I have done a lot of methods like createScaledBitmap
, or compress(CompressFormat.PNG, 20, stream);
or Bitmap.createBitmap(source, 0, 0, source.getWidth(),source.getHeight(), m, true);
also searched a lot of methods.
But it's not reducing the size as much as I want. it still remains in 2.2+ MB per png.
Any idea other than these. Thanks.
Asked
Active
Viewed 146 times
0

n1nsa1d00
- 856
- 9
- 23

Hussnain Muavia
- 3
- 6
-
I am also building a app which deals with High resolution images. But on server side I am compressing and re-size the image on server side by using "thumbnailator-0.4.8.jar". – aviundefined Jun 06 '15 at 21:37
-
You will find info on this question/answer helpful. http://stackoverflow.com/a/10652312/940834 – IAmGroot Jun 06 '15 at 21:48
-
A Bitmap uses a lot of memory. If the PNG is 2.2+MB, you can assume the Bitmap is going to be even larger. You need to compress to a lossy image format (JPEG), or reduce the size/quality of the PNG. You're probably better off converting to JPG. – Eugene K Jun 07 '15 at 00:10
-
Try using `compress(CompressFormat.JPEG, 50, stream);` – Phantômaxx Jun 07 '15 at 07:48
-
@Der Golem, Sir i am bounded to use only .png images, i can't use jpeg images – Hussnain Muavia Jun 07 '15 at 18:47
-
@Eugene K , i already tried this method, but its not working, and i need only png images not jpeg. So, even i set to compress(CompressFormat.PNG, 0, stream); but its still give me about 2Mb of bitmap, secondly i also used createBitmap method to resize or crop the image but its not working or the image intensity is much higher that my app still crashing.. – Hussnain Muavia Jun 07 '15 at 18:52
1 Answers
0
I am also building an app which deals with high resolution images but on server side. I am compressing and re-sizing the image on server side by using thumbnailator-0.4.8.jar. Example
InputStream in = new ByteArrayInputStream(bytes);
BufferedImage bImageFromConvert = ImageIO.read( in );
BufferedImage newImage = Thumbnails.of(bImageFromConvert).size(213, 316).asBufferedImage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(newImage, "jpg", baos);
baos.flush();
retVal = baos.toByteArray();
baos.close();

n1nsa1d00
- 856
- 9
- 23

aviundefined
- 802
- 2
- 10
- 25