1

I am working on an app.

In which I need to compress image same as Whatsapp does in their app.

I have tried with many solutions such as:

Image compression like Whatsapp and other messengers on Android

I have followed all the solutions above which is not generating the perfect result as Whatsapp does.

The size is different from Whatsapp after compressing.

Is their any other solutions that do exact the same compress algorithm from Whatsapp.

Any help will be greatly appreciated.

Community
  • 1
  • 1
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
  • 5
    WhatsApp is not open source. To get "the same compress algorithm" and avoid "size is different", you would need their source code. – CommonsWare Apr 27 '16 at 17:05
  • Possible duplicate of [Compress camera image before upload](http://stackoverflow.com/questions/19594152/compress-camera-image-before-upload) – Angel Koh Apr 27 '16 at 17:08
  • too late but you need to check it once -http://voidcanvas.com/whatsapp-like-image-compression-in-android/ – Adil Feb 09 '18 at 05:51

1 Answers1

0

you can try one of the following first

or

FileOutputStream out = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bmp = BitmapFactory.decodeFile(photoPath, options);
try {
out = new FileOutputStream(filename);
bmp.compress(CompressFormat.JPEG, 70, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
    if (out != null) {
        out.close();
    }
} catch (IOException e) {
    e.printStackTrace();
}
}

70 is the quality parameter if you want to reduce the size reduce the value of quality

Community
  • 1
  • 1
Nishant Dixit
  • 5,388
  • 5
  • 17
  • 29