From d13635e00bc80a990dc92eb3416a1ead899650a6 Mon Sep 17 00:00:00 2001
From: 18034727885 <973609879@qq.com>
Date: 星期四, 02 四月 2026 17:55:40 +0800
Subject: [PATCH] 优化图片压缩
---
app/src/main/java/com/jxonlinecar/driver/base/local/BasePhotoActivity.kt | 35 +++++++----------------------------
app/build.gradle | 2 ++
2 files changed, 9 insertions(+), 28 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index a8e21f6..b59c570 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -123,4 +123,6 @@
implementation 'com.huaweicloud:esdk-obs-android:3.21.12'
//圆形图片控件
implementation 'de.hdodenhof:circleimageview:3.1.0'
+ //图片压缩
+ implementation 'top.zibin:Luban:1.1.8'
}
diff --git a/app/src/main/java/com/jxonlinecar/driver/base/local/BasePhotoActivity.kt b/app/src/main/java/com/jxonlinecar/driver/base/local/BasePhotoActivity.kt
index 3819fab..2fb17c4 100644
--- a/app/src/main/java/com/jxonlinecar/driver/base/local/BasePhotoActivity.kt
+++ b/app/src/main/java/com/jxonlinecar/driver/base/local/BasePhotoActivity.kt
@@ -35,6 +35,7 @@
import com.ypx.imagepicker.builder.MultiPickerBuilder
import kotlinx.android.synthetic.main.dialog_phone.view.*
import org.jetbrains.anko.toast
+import top.zibin.luban.Luban
import java.io.*
@@ -194,33 +195,11 @@
Thread(
Runnable
{
- var copyFile = ""
- if (filePath.endsWith("png") || filePath.endsWith("jpg")) {
- getCameraPhotoOrientation(filePath)
- try {
- copyFile = compressImage(filePath)
- } catch (e: java.lang.Exception) {
- e.printStackTrace()
- }
- if (copyFile.isNullOrEmpty()) {
- runOnUiThread {
- showNum--
- dismissDialog()
- toast("文件已损坏,无法上传")
- }
- return@Runnable
- }
-// val bitmap = getBitmapFormUri(this,uri)
-// val bit = rotateBitmap(bitmap, rotate)
-// val b = saveBmpToPath(bit, filePath)
-// if (!b) {
-// Handler(mainLooper).post {
-// toast("旋转图片错误")
-// }
-// }
- }
- val file = File(copyFile.ifEmpty { filePath });
- val resourceUrl = uploadManager.uploadHWSync(file);
+ val copyFile =
+ Luban.with(this).load(filePath).setTargetDir(filesDir.absolutePath).get()
+ .first()
+ Log.d(TAG, "savePhone: copyFile:$copyFile")
+ val resourceUrl = uploadManager.uploadHWSync(copyFile);
runOnUiThread {
showNum--
Log.d("showNum==", "showNum==========" + showNum.toString())
@@ -228,7 +207,7 @@
if (showNum <= 0)
dismissDialog()
resourceUrl?.also {
- getPhoneUrl(it, type, copyFile)
+ getPhoneUrl(it, type, copyFile.absolutePath)
getPhoneUrl(it, type)
}
}
--
Gitblit v1.7.1