# ImageCompressor **Repository Path**: Rickyal/ImageCompressor ## Basic Information - **Project Name**: ImageCompressor - **Description**: 基于LibJpeg实现的图片压缩库,在保证质量的情况下,极致压缩,可以达到类似微信聊天图片的压缩效果 - **Primary Language**: Kotlin - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-17 - **Last Updated**: 2023-03-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ImageCompress [![](https://jitpack.io/v/RickyHal/ImageCompressor.svg)](https://jitpack.io/#RickyHal/ImageCompressor) English | [中文](/README.zh.md) An Android image compression library based on libjpeg can extremely compress the image size while ensuring the quality. See the following for the specific compression effect. For the implementation principle, see[blog](https://juejin.cn/post/6844904014442659853#heading-6) Add it in your root build.gradle at the end of repositories: allprojects { repositories { ... maven { url 'https://jitpack.io' } } } Step 2. Add the dependency dependencies { implementation 'com.github.RickyHal:ImageCompressor:1.0' } ## How to use bitmap compress to bitmap ```Java /** * Compress bitmap API * * @param context * @param srcBitmap src bitmap * @param quality compress quality 0-100 * @param format compress format * @return dst bitmap */ public static Bitmap compressBitmap(Context context, Bitmap srcBitmap, int quality, @Nullable Bitmap.CompressFormat format); ``` ```kotlin // compress bitmap val dstBitmap = CompressUtil.compressBitmap(BaseApplication.gContext, srcBitmap, quality, Bitmap.CompressFormat.JPEG) ``` or bitmap compress to file ```Java // API public native static int compressBitmap(Bitmap bitmap, int quality, String destFile); ``` ```kotlin // compress CompressUtil.compressBitmap(srcBitmap, quality, destPath) ``` # Compression effect * Original picture(2080*4413)5.56MB * quality90%(2080*4413)1.87MB cost 977ms * quality80%(2080*4413)1.18MB cost 916ms * quality70%(2080*4413)918KB cost 902ms * quality60%(2080*4413)735KB cost 870ms * quality50%(2080*4413)622KB cost 857ms * quality40%(2080*4413)519KB cost 858ms * quality30%(2080*4413)420KB cost 839ms * quality20%(2080*4413)315KB cost 828ms * quality10%(2080*4413)199KB cost 819ms * quality5%(2080*4413)129KB cost 809ms * quality1%(2080*4413)91.8KB cost 808ms ## License > ``` > Copyright 2021 RickyHal > > Licensed under the Apache License, Version 2.0 (the "License"); > you may not use this file except in compliance with the License. > You may obtain a copy of the License at > > http://www.apache.org/licenses/LICENSE-2.0 > > Unless required by applicable law or agreed to in writing, software > distributed under the License is distributed on an "AS IS" BASIS, > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > See the License for the specific language governing permissions and > limitations under the License. > ```