From 3013b813e5df6977c0be921928f73b1a3adde290 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 02 七月 2025 15:52:04 +0800
Subject: [PATCH] ### 一、巡查模块相关
---
app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java | 36 ++++++++++++++++++++----------------
1 files changed, 20 insertions(+), 16 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..ad38672 100644
--- a/app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java
+++ b/app/src/main/java/cn/flightfeather/thirdappmodule/task/CompressPhotoTask.java
@@ -47,38 +47,42 @@
String fileName = mediafile.getGuid()+".jpg";
File outputFile = new File(Environment.getExternalStorageDirectory(),path+fileName);
outputFile.getParentFile().mkdirs();
+
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);
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