简体   繁体   中英

Compress image without losing the quality

I've been developing an Android app which takes picture and save it. And I want make the upload speed more faster by compressing the image. But as I compressed them using BitmapCompress , the image seems lost its quality. Here :

RAW :

在此处输入图片说明

COMPRESSED :

在此处输入图片说明

BEFORE : DIMENSION - 1920X1920 FILE SIZE - 2.94MB

AFTER : DIMENSION - 960X960 FILE SIZE - 644KB

I wonder if there's a way, a library perhaps that will solve my problem? Instagram seems to be doing this compression stuff without losing the image quality.

Compressing will always lead to decreased quality in the one or the other way.

Here is what you could do:

  • Change your compression format to PNG, if you are not already using that.
  • Find a perfect compromise for the quality value between size and quality

I agree with @Saret BitmapCompress will decrease the file size with a good quality. You can get ~800-900KB photo from ~3MB photo using 80% quality compressing without scaling. You can get better result if you crop the photo.

If you don't care scaling and details in depth are not important for you, I strongly recommend following libraries:

Bitmap yourbitmap

[...]

OutputStream os = new FileOutputStream(filename); 
yourbitmap.compress(CompressFormat.JPEG, 80, os);  // 80% compression

This will keep your image light and with a good quality.

Some keywords worth looking into:

  • 'EXIF removal' libraries
  • 'lossless compression' libraries

Explanations:

Remove some of the excess EXIF data

You can try reducing filesize by removing the EXIF data that is stored in the image. In many cases, the EXIF data takes up a lot of room, and often contains more information than the user might need for their use case.

A quick google search shows the following tool could be helpful in removing the EXIF data. Has Windows and Mac versions:

http://www.exifpurge.com/

As for a tool that would work in your android build process, that needs further searching. But at least 'EXIF removal android library' are good keywords to start with

Lossless compression

Another alternative is researching lossless compression. I've used them in the past in web development. In my case, I used libraries which worked from the command line together with 'grunt' a build tool.

A quick google search showed the following site which works direct from your browser.

https://compressor.io/compress

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM