Use of Android tiny integrated picture compression framework
In order to simplify the call to image compression and provide the most concise and reasonable API compression logic, for the compression of bitmap, the optimal size is dynamically adapted according to the screen resolution, and for the compression of file to optimize the underlying libjpeg, the whole image compression process is compressed in different steps in the compression thread pool, and then distributed back to the UI thread.
Supported compression types
Types of compressed data sources supported by tiny picture compression framework:
1、Bytes 2、File 3、Bitmap 4、Stream 5、Resource 6、Uri(network、file、content)
Tiny supports single data source compression and batch compression. Supported compression types:
1. Data source ― > compress as bitmap 2, data source ― > compress as file 3, data source ― > compress as file and return compressed bitmap 4, batch data source ― > batch compress as bitmap 5, batch data source ― > batch compress as file 6, batch data source ― > batch compress as file and return compressed bitmap
Compression parameters
Tiny.BitmapCompressOptions
There are three configurable bitmap compression parameters:
1、width 2、height 3、Bitmap.Config
If not configured, tiny will dynamically adapt according to the screen and use ARGB by default_ eight thousand eight hundred and eighty-eight
Tiny.FileCompressOptions
Four file compression parameters can be configured:
1. Quality - compression quality, the default is 76 2. Iskeepsampling - whether to maintain the width and height of the original data source picture 3. Filesize - compressed file size 4. Outfile - compressed file storage path
If it is not configured, tiny will compress according to the default compression quality. The compressed files are stored in the directory of externalstorage / Android / data / ${packagename} / tiny / by default
Tiny project address: https://github.com/tianyingzhong/Tiny
Compression ratio comparison between tiny and wechat circle of friends
The following is an example of compression effect comparison using tiny picture compression library:
Compress to bitmap
Compress to file
Compress to file and return bitmap
Batch compression to bitmap
Batch compression to file
Batch compress to file and return bitmap
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.