Browse Source

修改压缩最大宽度与高度为屏幕宽度与高度

zengjiebin 8 years ago
parent
commit
d78ed953f0
1 changed files with 9 additions and 1 deletions
  1. 9 1
      app/src/main/java/com/kfzs/duanduan/react/upfile/UpFileUtils.java

+ 9 - 1
app/src/main/java/com/kfzs/duanduan/react/upfile/UpFileUtils.java

@@ -1,8 +1,11 @@
 package com.kfzs.duanduan.react.upfile;
 
 
+import android.graphics.Bitmap;
+
 import com.nanchen.compresshelper.CompressHelper;
 import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.G;
 import com.zhy.http.okhttp.OkHttpUtils;
 import com.zhy.http.okhttp.callback.Callback;
 
@@ -59,7 +62,12 @@ public class UpFileUtils {
         if (index < photos.size()) {
             File file;
             if ((file = new File(photos.get(index))).exists()) {
-                File newFile = CompressHelper.getDefault(SheepApp.getInstance()).compressToFile(file);
+                File newFile = new CompressHelper.Builder(SheepApp.getInstance())
+                        .setMaxWidth(G.WIDTH)  // 默认最大宽度为720
+                        .setMaxHeight(G.HEIGHT) // 默认最大高度为960
+                        .setQuality(80)    // 默认压缩质量为80
+                        .setCompressFormat(Bitmap.CompressFormat.JPEG) // 设置默认压缩为jpg格式
+                        .build().compressToFile(file);
 //                org.xutils.common.util.FileUtil.copy(newFile.getAbsolutePath(), ClassFileHelper.DIR+"/1.png");
                 OkHttpUtils.post()
                         .addFile("uploadfile", "1.png", newFile)//