LuckSiege / PictureSelector

Picture Selector Library for Android or 图片选择器
Apache License 2.0
13.25k stars 3.01k forks source link

setCompressEngine设置压缩后,拿不到压缩后的图片地址 #2800

Open Jin-Din opened 9 months ago

Jin-Din commented 9 months ago

Current use version?

当前使用的版本是多少?

3.11.1

Will this problem occur in demo?

Demo能否复现这问题?

Describe the problem or provide an error log?

描述问题或提供错误log?

在setCompressEngine中使用鲁班luban后,forResult回调函数里的localmedia.getCompressPath() 一直null,感觉是没有把compresspath传出来。 检查了一下图片压缩后的存储路径,存在被压缩后的图片,但在forresult回调函数的 localmedia.getCompressPath() 却为null

image

 PictureSelector.create(FreeDrawActivity.this)
                .openGallery(SelectMimeType.TYPE_IMAGE)
                .setSelectionMode(SelectModeConfig.SINGLE)
                .isDisplayCamera(true)
                .isPreviewImage(true) // 是否可预览图片 true or false
                .isDirectReturnSingle(true)
                .setImageEngine(GlideEngine.createGlideEngine())
                .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
                .setCompressEngine((CompressFileEngine) (context, source, call) -> {
                    //bug: 压缩后的地址没有传到localMedia.getCompressPath()。 PictureSelector3.0 的 Bug?? 
                    Luban.with(context).load(source)
                            .setTargetDir(SystemDirPath.getDefaultProjectWorkspaceTempDir()) //设置压缩的临时存储
                            .ignoreBy(100).setCompressListener(new OnNewCompressListener() {
                                @Override
                                public void onStart() {

                                }

                                @Override
                                public void onSuccess(String source, File compressFile) {
                                    if (call != null) {
                                        call.onCallback(source, compressFile.getAbsolutePath());
                                    }
                                }

                                @Override
                                public void onError(String source, Throwable e) {
                                    if (call != null) {
                                        call.onCallback(source, null);
                                    }
                                }
                            }).launch();
                })

                .forResult(new OnResultCallbackListener<LocalMedia>() {
                    @Override
                    public void onResult(ArrayList<LocalMedia> selectList) {

                        if (selectList.size() > 0) {
                            LocalMedia localMedia = selectList.get(0);
                            //获取压缩后的路径
                            String path = localMedia.getPath();
                            // 这里返回的compressPath 为null
                            String compressPath = localMedia.getCompressPath();
                            String realPath = localMedia.getRealPath();
                            String availablePath = localMedia.getAvailablePath();

                            if (new File(compressPath).exists()) //这里拿到的压缩后的地址为null
                                img_open(compressPath);
                            else {
                                img_open(realPath);
                            }

                        }

                    }

                    @Override
                    public void onCancel() {

                    }
                });
xiaoouzcc commented 9 months ago

请问解决了吗?

19120784184 commented 8 months ago

因为在PictureCommonFragment中被过滤了,就是下面这个判断,有些照片能正常返回,有些不能返回的原因就是判断不生效if (!TextUtils.isEmpty(compressPath) && (compressPath.contains("Android/data/") || compressPath.contains("data/user/")))

me-sendy commented 7 months ago

请问解决了? 今天我也遇到这个问题了。

19120784184 commented 7 months ago

请问解决了? 今天我也遇到这个问题了。

最新版本还没解决,如果压缩是必要的,建议获取图片原始路径手动压缩