From 4c9c2a82fa4c90d3794b87bf7031a62c175a1df2 Mon Sep 17 00:00:00 2001 From: jeanboy Date: Fri, 23 Jun 2017 18:19:27 +0800 Subject: [PATCH] optimize --- README.md | 28 +++++++++++++++++-- .../main/java/net/bither/util/NativeUtil.java | 7 ++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 775d661..8f0d54c 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,41 @@ Android图片压缩目前最优解决方案。 ------ -##介绍 +## 介绍 Android图片压缩结合多种压缩方式,常用的有尺寸压缩、质量压缩以及通过JNI调用libjpeg库来进行压缩,三种方式结合使用实现指定图片内存大小,清晰度达到最优。 -##使用 +## 使用 * 导入lib-bither-compress + ```java NativeUtil.compressBitmap(bitmap, savePath); + + NativeUtil.compressBitmap(bitmap, savePath, maxByte, quality); +``` + +* 图像建议尺寸 + +```Java + public final static int QUALITY_320P = 320;//480, 320 + public final static int QUALITY_360P = 360;//640, 360 + public final static int QUALITY_480P = 480;//640, 480 + public final static int QUALITY_720P = 720;//1280, 720 + public final static int QUALITY_1080P = 1080;//1920, 1080 + public final static int QUALITY_2K = 1440;//2560, 1440 + public final static int QUALITY_4K = 2160;//3840, 2160 ``` +* 图像默认品质 + +```Java + //见 NativeUtil 中 compressBitmap(bitmap, savePath, maxByte, quality) 方法 + int options = 80;//100不压缩品质 +``` + +> 注意:默认将图像压缩到 1280*720 的尺寸,品质为 80 ,图像大小为 1 MB。其他配置可在 lib-bither-compress 中 NativeUtil 下自己配置。 + ## 对比 原图 5.5M diff --git a/lib-bither-compress/src/main/java/net/bither/util/NativeUtil.java b/lib-bither-compress/src/main/java/net/bither/util/NativeUtil.java index 42de7c5..94f33c6 100644 --- a/lib-bither-compress/src/main/java/net/bither/util/NativeUtil.java +++ b/lib-bither-compress/src/main/java/net/bither/util/NativeUtil.java @@ -4,12 +4,9 @@ import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Rect; -import android.util.Log; import java.io.ByteArrayOutputStream; -import static android.media.CamcorderProfile.QUALITY_720P; - public class NativeUtil { public final static int QUALITY_320P = 320;//480, 320 @@ -22,11 +19,11 @@ public class NativeUtil { public final static int QUALITY_DEFAULT = QUALITY_720P; public final static int SIZE_1KB = 1024; - public final static int size_1MB = SIZE_1KB * 1024; + public final static int SIZE_1MB = SIZE_1KB * 1024; public static void compressBitmap(Bitmap bitmap, String filePath) { - compressBitmap(bitmap, filePath, size_1MB, QUALITY_DEFAULT); + compressBitmap(bitmap, filePath, SIZE_1MB, QUALITY_DEFAULT); } public static void compressBitmap(Bitmap bitmap, String filePath, int maxByte, int quality) {