Curzibn / Luban

Luban(鲁班)—Image compression with efficiency very close to WeChat Moments/可能是最接近微信朋友圈的图片压缩算法
Apache License 2.0
13.58k stars 2.25k forks source link

压缩无效,返回原图片的相对路径 #397

Open oudengding opened 3 years ago

oudengding commented 3 years ago

android 11, 没有使用setTargetDir()方法,压缩后返回原图片的相对路径

代码: Luban.with(context) .load(uri) .ignoreBy(100) //.setTargetDir(dir.getAbsolutePath()) .filter(path -> { return !(TextUtils.isEmpty(path)); }) .setCompressListener(onCompressCallback) .launch();

压缩后的图片:/camera_photos/Pictures/JPEG_20211011_140125.jpg

Muran-Hu commented 2 years ago

@Luban Hey guys, hope everything going well! That would be nice if you have time to look into this problem, thanks in advance! 🙏🏾

I encountered the same problem when I was testing on the Android 12 emulator and set back camera from VirtualScene to Emulated(#430 and #428), as the following code shows:

Luban.with(mContext)
    .load(file)
    .ignoreBy(100)
    .setTargetDir(getPath())
    .setCompressListener(object : OnCompressListener {
        override fun onStart() {}
        override fun onSuccess(compressedFile: File) {
            refreshDataSource(compressedFile.path)
        }

        override fun onError(e: Throwable) {
            e.printStackTrace()
        }
    })
    .launch()
}

Although I invoked the setTargetDir() method to set the compressed file directory, the original image path returned in the callback method onSuccess().

  1. Before compression:/storage/emulated/0/Android/data/com.xxx.test/files/Pictures/JPEG_20220310_2140888612150486718.jpg
  2. After compression:/storage/emulated/0/Android/data/com.xxx.test/files/Pictures/JPEG_20220310_2140888612150486718.jpg
  3. getPath - /storage/emulated/0/Android/data/com.xxx.test/files/compress/

Thank you again and best regards. Looking forward to the fix! 🤝