Skip to content

RickyHal/ImageCompressor

Repository files navigation

ImageCompress

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'
}

How to use

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)

Compression effect

  • Original picture(2080*4413)5.56MB Original picture

  • quality90%(2080*4413)1.87MB 耗时977ms quality90%

  • quality80%(2080*4413)1.18MB 耗时916ms quality80%

  • quality70%(2080*4413)918KB 耗时902ms quality70%

  • quality60%(2080*4413)735KB 耗时870ms quality60%

  • quality50%(2080*4413)622KB 耗时857ms quality50%

  • quality40%(2080*4413)519KB 耗时858ms quality40%

  • quality30%(2080*4413)420KB 耗时839ms quality30%

  • quality20%(2080*4413)315KB 耗时828ms quality20%

  • quality10%(2080*4413)199KB 耗时819ms quality10%

  • quality5%(2080*4413)129KB 耗时809ms quality5%

  • quality1%(2080*4413)91.8KB 耗时808ms quality1%

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.

About

基于libjpeg实现的Android图片压缩库

Resources

License

Stars

Watchers

Forks

Packages

No packages published