English | 中文
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, seeblog
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'
}
bitmap compress to bitmap
/**
* 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);
// compress bitmap
val dstBitmap = CompressUtil.compressBitmap(BaseApplication.gContext, srcBitmap, quality, Bitmap.CompressFormat.JPEG)
or bitmap compress to file
// API
public native static int compressBitmap(Bitmap bitmap, int quality, String destFile);
// compress
CompressUtil.compressBitmap(srcBitmap, quality, destPath)
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.