Skip to content

PictureSelector 3.0 如何压缩?

Luck edited this page Apr 5, 2022 · 4 revisions

以Luban压缩为例:

.setCompressEngine(new CompressFileEngine() {
            @Override
            public void onStartCompress(Context context, ArrayList<Uri> source, OnKeyValueResultCallbackListener call) {
                   Luban.with(context).load(source).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();
                        }
                    });