Joke Collection Website - Mood Talk - Android Image Compression Library —— Talking about how to compress images in Android

Android Image Compression Library —— Talking about how to compress images in Android

Android black technology, the ultimate image compression 1. Support custom configuration, no distortion, batch processing.

Second, why should the image upload be compressed?

1, the space of the picture server is limited, and the disk is expensive.

2. The network is unstable, and large files need to be resumed at breakpoints.

3. Avoid Android OOM exceptions as much as possible.

4. The rule of consent in the context

5. Applications that need to upload original images include hospital clinical projects and financial banks.

Third, the process of image compression.

1. Recursing each picture

2, set the picture format

Papua new guinea, jpg, webp

3. Quality compression (format, quality, baos)

Because png is lossless compression, the setting quality is invalid (not suitable as a thumbnail).

Sampling rate compression

Reduce the picture resolution, reduce the occupied disk space and memory size.

Scaling compression (bitmap, empty, rectangle, empty)

Reduce the pixels of the picture, reduce the occupied disk space and memory size, which can be used to cache thumbnails.

JNI calls JPEG library

The image engine of Android uses the castrated skia engine and removes the Huffman algorithm in image compression.

4, pixel repair

5. Return to the compressed state

6. Complete compression.

Demo:

Reference:

Luban framework

disadvantaged

1. When the compression path is not set, the thrown exception will not flash back.

2. In the source code, the compression ratio is fixed at 60 and cannot be modified.

3, compressed configuration, parameters are not suitable for real project requirements.

4. The compression size cannot be specified, for example, within 100KB.

How to compress pictures in Android? At present, there are two ways to compress pictures:

Pictures exist in three forms:

The size of bigmap in memory is calculated in pixels, that is, width * height, so if you need to display photos in Android, you must compress them in proportion to prevent the APP from quitting because of excessive memory consumption.

Isn't it simple? O(∩_∩)O haha ~

Android image compression-size and quality compression and image preservation i. Preface:

2. Mass compression

note:

Empty before the second compression (). Then compress (quality, treasure);

Sometimes we use mass compression without effect. Maybe the quality of each compression is too small. You can try to modify the compression quality to 10.

Prompt for mass compressor, 0- 100. 0 means compression.

Small size, 100 means maximum mass compression. some

Formats, such as lossless PNG, ignore quality settings;

3. Mixed mode compression

Link: