From fbae5f3ea74727ccadc48314a864a1ea0099a945 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 17 十月 2025 17:36:17 +0800
Subject: [PATCH] 2025.10.17 1、新增巡查时,修改工地施工阶段功能(待完成)

---
 app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java b/app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java
index 3bfa182..69a2787 100644
--- a/app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java
+++ b/app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java
@@ -42,43 +42,50 @@
     @Override
     protected Object doInBackground(Object[] objects) {
         outputFIleList = new ArrayList<>();
-        for (Mediafile mediafile:mediafileList){
+        for (int i = 0; i < mediafileList.size(); i++) {
+            Mediafile mediafile = mediafileList.get(i);
             File file = new File(Environment.getExternalStorageDirectory(),(mediafile.getPath()+mediafile.getDescription()));
             String fileName = mediafile.getGuid()+".jpg";
             File outputFile = new File(Environment.getExternalStorageDirectory(),path+fileName);
-            outputFile.getParentFile().mkdirs();
+            if (!outputFile.getParentFile().mkdirs()) continue;
+
             BitmapFactory.Options opts = new BitmapFactory.Options();
             //灏嗗浘鐗囩殑闀垮缂╁皬涓�1/2
             opts.inSampleSize = 2;
-            Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath(),opts);
+            Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath(), opts);
+//            if (bm == null) continue;
+
             int aa = bm.getHeight();
             int bb = bm.getWidth();
-            Log.i("bitmap",bm.getHeight()+" "+bm.getWidth());
+            Log.i("bitmap", bm.getHeight() + " " + bm.getWidth());
             //鍘嬬缉缂╃暐鍥�
             Bitmap bmSmall = null;
             int normalSize = 1440;
-            int width,height = 0;
-            if (bm.getWidth()>=bm.getHeight()){
+            int width, height = 0;
+            if (bm.getWidth() >= bm.getHeight()) {
                 width = normalSize;
-                height = normalSize*bm.getHeight()/bm.getWidth();
-            }else {
-                height =normalSize;
-                width = normalSize*bm.getWidth()/bm.getHeight();
+                height = normalSize * bm.getHeight() / bm.getWidth();
+            } else {
+                height = normalSize;
+                width = normalSize * bm.getWidth() / bm.getHeight();
             }
 
-            if (bm!=null){
-                bmSmall= Bitmap.createScaledBitmap(bm,width,height,true);
+            if (bm != null) {
+                bmSmall = Bitmap.createScaledBitmap(bm, width, height, true);
                 try {
-                    bmSmall.compress(Bitmap.CompressFormat.JPEG, 80, new FileOutputStream(outputFile.getAbsolutePath()));
-                    Log.i("compress success",outputFile.getAbsolutePath());
+                    // 褰撳浘鐗囧ぇ浜�1MB鏃讹紝鎵嶄細杩涜鍘嬬缉澶勭悊
+                    if (file.length() > 1024L * 1024) {
+                        bmSmall.compress(Bitmap.CompressFormat.JPEG, 80, new FileOutputStream(outputFile.getAbsolutePath()));
+                    } else {
+                        bmSmall.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(outputFile.getAbsolutePath()));
+                    }
+                    Log.i("compress success", outputFile.getAbsolutePath());
                     outputFIleList.add(outputFile);
-                        bm.recycle();
-                        bm=null;
+                    bm.recycle();
                     bmSmall.recycle();
-                    bmSmall =null;
                 } catch (FileNotFoundException e) {
                     e.printStackTrace();
-                    Log.i("compress failure",outputFile.getAbsolutePath());
+                    Log.i("compress failure", outputFile.getAbsolutePath());
                 }
             }
         }

--
Gitblit v1.9.3