18034727885
2026-04-02 d13635e00bc80a990dc92eb3416a1ead899650a6
优化图片压缩
2个文件已修改
37 ■■■■■ 已修改文件
app/build.gradle 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/jxonlinecar/driver/base/local/BasePhotoActivity.kt 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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'
}
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)
                    }
                }