Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanboy committed Jun 23, 2017
1 parent f522730 commit 4c9c2a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 4c9c2a8

Please sign in to comment.