Skip to content

Commit 2b5f253

Browse files
author
xiaoqi
committed
update to 1.2.0
1 parent 842b868 commit 2b5f253

File tree

14 files changed

+159
-129
lines changed

14 files changed

+159
-129
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ a lightweight image compress framework for Android based on libJpeg.
3636
增加autoRecycle的设置(只有压缩bitmap和压缩byte类型的图片有用,其他类型图片无效),开启该设置代表自动会将传入的bitmap或者bytes进行内存回收;
3737
1.1.6 增加compressFileSize的压缩设置,可以设置当大于一定kb大小的图片,才会进行压缩,只对压缩保存到本地的方法有效,对压缩保存到bitmap的方法无效;
3838
1.1.7 默认对gif不支持压缩
39-
1.1.9 修复bug
39+
1.1.9 修复bug
40+
1.2.0 增加Bitmap.Config的设置,默认是RGB_565,可以在CompressArgs设置,也可以在LightConfig统一配置
4041

4142
### 使用方法:
4243

4344
android {
4445
...
4546
ndk {
46-
abiFilters 'armeabi-v7a', 'armeabi', 'x86'
47+
abiFilters 'armeabi-v7a', 'armeabi'
4748
}
4849
}
4950
@@ -68,10 +69,11 @@ a lightweight image compress framework for Android based on libJpeg.
6869
5.autoRotation: 是否要将图片自动摆正,只有压缩从本地读取图片有用,其他情况无效(例如三星手机拍照后图片会自动旋转,设为true则会自动将图片旋转正确的方向)。
6970
6.autoRecycle: 是否需要自动将传入的bitmap或者bytes进行内存回收,只有压缩bitmap和压缩byte类型的图片有用,其他类型图片无效
7071
7.compressFileSize: 对压缩图片到本地的时候增加文件大小的设置,如果大于此kb大小的图片,则不进行压缩。
72+
8.bitmapConfig: 设置bitmap的色彩模式,默认是RGB_565
7173
因为从网络下载图片保存到本地,中间默认会自动压缩图片,如果不想对图片进行压缩,并保持宽高的话,设置如下参数即可:
7274

7375
CompressArgs args = new CompressArgs.Builder().quality(100).ignoreSize(true).autoRotation(true)
74-
.autoRecycle(true).build();
76+
.autoRecycle(true).bitmapConfig(Bitmap.Config.ARGB_8888).build();
7577

7678

7779
##### 默认参数:

app/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ android {
2424
jniLibs.srcDirs = ['libs']
2525
}
2626
}
27-
2827
splits {
2928
abi {
3029
enable true
@@ -33,11 +32,11 @@ android {
3332
universalApk true
3433
}
3534
}
36-
3735
compileOptions {
3836
sourceCompatibility JavaVersion.VERSION_1_8
3937
targetCompatibility JavaVersion.VERSION_1_8
4038
}
39+
buildToolsVersion '26.0.2'
4140
}
4241

4342
dependencies {
@@ -47,8 +46,8 @@ dependencies {
4746
testImplementation 'junit:junit:4.12'
4847
androidTestImplementation 'com.android.support.test:runner:1.0.1'
4948
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
50-
// implementation 'com.noober.light:core:1.1.6'
51-
implementation project(':light')
49+
implementation 'com.noober.light:core:1.2.0'
50+
// implementation project(':light')
5251
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
5352
implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
5453
}

app/src/main/java/com/light/example/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
120120
BitmapFactory.decodeFile(path, options);
121121
// Bitmap compressBitmap = Light.getInstance().compress(imageUri);
122122
CompressArgs args = new CompressArgs.Builder().width(1600)
123+
.bitmapConfig(Bitmap.Config.ARGB_8888)
123124
.height(1600).autoRotation(true).compressFileSize(200)
124125
.build();
125126
Light.getInstance().compress(imageUri, args, path1);

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
android:id="@+id/image_compress"
2222
android:layout_width="match_parent"
2323
android:layout_height="wrap_content"
24-
android:scaleType="fitXY"/>
24+
android:scaleType="centerCrop"/>
2525

2626
<TextView
2727
android:id="@+id/tv_info1"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ext {
3030
userOrg = 'noober'
3131
groupId = 'com.noober.light'
3232
uploadName = 'Light'
33-
publishVersion = '1.1.9'
33+
publishVersion = '1.2.0'
3434
desc = "a light weight image compress framework for Android based on libjpeg"
3535
website = 'https://github.com/JavaNoober/Light'
3636
// gradlew clean build bintrayUpload -PbintrayUser=xiaoqiandroid -PbintrayKey=xxxxxxxxxxxxxxxx -PdryRun=false

light/src/main/java/com/light/body/CompressArgs.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.light.body;
22

33

4+
import android.graphics.Bitmap;
5+
46
/**
57
* Created by xiaoqi on 2018/1/10
68
*/
@@ -14,16 +16,18 @@ public class CompressArgs {
1416
private boolean autoRotation;
1517
private boolean autoRecycle;
1618
private int compressFileSize = -1;//kb
19+
private Bitmap.Config config;
1720

1821
private CompressArgs(){
1922

2023
}
2124

22-
public static CompressArgs getDefaultArgs(){
25+
public static CompressArgs getDefaultArgs(){
2326
LightConfig config = Light.getInstance().getConfig();
2427
return new Builder().width(config.getMaxWidth()).height(config.getMaxWidth())
2528
.quality(config.getDefaultQuality()).ignoreSize(config.isNeedIgnoreSize())
26-
.autoRecycle(config.isAutoRecycle()).autoRotation(config.isAutoRotation()).build();
29+
.autoRecycle(config.isAutoRecycle()).autoRotation(config.isAutoRotation())
30+
.bitmapConfig(config.getBitmapConfig()).build();
2731
}
2832

2933
public int getWidth() {
@@ -54,6 +58,10 @@ public int getCompressFileSize() {
5458
return compressFileSize;
5559
}
5660

61+
public Bitmap.Config getConfig() {
62+
return config;
63+
}
64+
5765
public void setCompressFileSize(int compressFileSize) {
5866
this.compressFileSize = compressFileSize;
5967
}
@@ -66,6 +74,8 @@ public static class Builder {
6674
private boolean autoRotation = Light.getInstance().getConfig().isAutoRotation();
6775
private boolean ignoreSize = Light.getInstance().getConfig().isNeedIgnoreSize();
6876
private boolean autoRecycle = Light.getInstance().getConfig().isAutoRecycle();
77+
private Bitmap.Config config = Light.getInstance().getConfig().getBitmapConfig();
78+
6979

7080
public Builder width(int width) {
7181
this.width = width;
@@ -102,6 +112,11 @@ public Builder compressFileSize(int compressFileSize){
102112
return this;
103113
}
104114

115+
public Builder bitmapConfig(Bitmap.Config config){
116+
this.config = config;
117+
return this;
118+
}
119+
105120
public CompressArgs build(){
106121
CompressArgs args = new CompressArgs();
107122
args.width = width;
@@ -111,6 +126,7 @@ public CompressArgs build(){
111126
args.autoRotation = autoRotation;
112127
args.autoRecycle = autoRecycle;
113128
args.compressFileSize = compressFileSize;
129+
args.config = config;
114130
return args;
115131
}
116132
}

light/src/main/java/com/light/body/LightConfig.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.light.body;
22

3+
import android.graphics.Bitmap;
4+
35
import com.light.core.Utils.DisplayUtil;
46

57
import java.io.Serializable;
@@ -28,7 +30,9 @@ public class LightConfig implements Serializable {
2830

2931
private boolean autoRecycle = false;
3032

31-
public static boolean isDebug = true;
33+
private Bitmap.Config bitmapConfig = Bitmap.Config.RGB_565;
34+
35+
public static boolean isDebug = true;
3236

3337
public LightConfig() {
3438
maxWidth = DisplayUtil.getScreenWidth(Light.getInstance().getContext());
@@ -100,4 +104,12 @@ public boolean isAutoRecycle() {
100104
public void setAutoRecycle(boolean autoRecycle) {
101105
this.autoRecycle = autoRecycle;
102106
}
107+
108+
public Bitmap.Config getBitmapConfig() {
109+
return bitmapConfig;
110+
}
111+
112+
public void setConfig(Bitmap.Config bitmapConfig) {
113+
this.bitmapConfig = bitmapConfig;
114+
}
103115
}

0 commit comments

Comments
 (0)