File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
android/src/main/java/com/theweflex/react Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -74,19 +74,24 @@ private static byte[] bitmapTopBytes(Bitmap bitmap) {
7474 }
7575
7676 private static byte [] bitmapResizeGetBytes (Bitmap image , int size ) {
77- // 这个压缩算法存在效率问题,希望有义士可以出手优化 by little-snow-fox 2019.10.20
77+ // little-snow-fox 2019.10.20
7878 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
7979 // 质量压缩方法,这里100表示第一次不压缩,把压缩后的数据缓存到 baos
8080 image .compress (Bitmap .CompressFormat .JPEG , 100 , baos );
81- int options = 10 ;
81+ int options = 100 ;
8282 // 循环判断压缩后依然大于 32kb 则继续压缩
8383 while (baos .toByteArray ().length / 1024 > size ) {
8484 // 重置baos即清空baos
8585 baos .reset ();
86- // 每次都减少1
87- options += 1 ;
86+ if (options <= 1 ) {
87+ break ;
88+ } else if (options > 5 ) {
89+ options -= 5 ;
90+ } else {
91+ options -= 1 ;
92+ }
8893 // 这里压缩options%,把压缩后的数据存放到baos中
89- image .compress (Bitmap .CompressFormat .JPEG , 10 / options * 10 , baos );
94+ image .compress (Bitmap .CompressFormat .JPEG , options , baos );
9095 }
9196 return baos .toByteArray ();
9297 }
Original file line number Diff line number Diff line change 11{
22 "name" : " react-native-wechat-lib" ,
3- "version" : " 1.1.5 " ,
3+ "version" : " 1.1.7 " ,
44 "description" : " react-native library for wechat app. 支持分享和拉起小程序。" ,
55 "main" : " index.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments