Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,压缩的话,怎么直接传list集合, #11

Closed
RookieExaminer opened this issue Apr 1, 2021 · 10 comments
Closed

你好,压缩的话,怎么直接传list集合, #11

RookieExaminer opened this issue Apr 1, 2021 · 10 comments

Comments

@RookieExaminer
Copy link

你好,压缩的话,怎么直接传list集合,

.load(list)

而不是
.load(uri, uri)

@forJrking
Copy link
Owner

如下

        val arrays = ArrayList<File>()
        Luban.with(this)                         //Lifecycle 获取,可以不填写参数也可使用ProcessLifecycleOwner
                .load(arrays)                          //_**支持 File,Uri,InputStream,String,和以上数据数组和集合**_
                .setOutPutDir(path)                      //输出目录文件夹
                .concurrent(true)          //多文件压缩是否并行,内部优化并行数量防止OOM
                .useDownSample(true)    //压缩算法 true采用邻近采样,否则使用双线性采样(纯文字图片效果绝佳)
                .format(Bitmap.CompressFormat.PNG)      //压缩后输出文件格式 支持 JPG,PNG,WEBP
                .ignoreBy(200)                     //期望大小,大小和图片呈现质量不能均衡所以压缩后不一定小于此值,
                .quality(95)                     //质量压缩系数  0-100
                .rename { "pic$it" }                    //文件重命名
                .filter { true }                        // 过滤器
                .compressObserver {
                    onSuccess = { }
                    onStart = {}
                    onCompletion = {}
                    onError = { e, s -> }
                }.launch()

@RookieExaminer
Copy link
Author

    val arrays = ArrayList<File>()

数组是 string类型的文件路径 是否可以?

@RookieExaminer
Copy link
Author

因为我使用的时候传入string类型的文件路径 list,报错,

@forJrking
Copy link
Owner

File,Uri,InputStream,String,和以上数据 单个、数组、集合 都支持的 具体报错显示什么错误

@RookieExaminer
Copy link
Author

2021-04-01 15:01:28.625 9306-9306/com.pinet.cloth.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pinet.cloth.android, PID: 9306
java.io.IOException: Incoming data type exception, it must be String, File, Uri
at d.l.a.c$b.e(Luban.kt:107)
at d.l.a.f.a.a(InputStreamAdapter.kt:26)
at com.forjrking.lubankt.Builder$compress$2.invokeSuspend(Luban.kt:253)
at com.forjrking.lubankt.Builder$compress$2.invoke(Unknown Source:10)
at g.a.h3.b.e(Undispatched.kt:91)
at g.a.h.e(Builders.common.kt:160)
at g.a.f.g(Unknown Source:1)
at com.forjrking.lubankt.Builder.f(Luban.kt:247)
at com.forjrking.lubankt.MultiRequestBuild$asyncRun$1$invokeSuspend$$inlined$map$1$2$lambda$1.invokeSuspend(Luban.kt:346)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at g.a.t0.run(DispatchedTask.kt:56)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
at d.l.a.b$b.run(Luban.kt:390)

@RookieExaminer
Copy link
Author

我传入的是string 类型的图片路径 list ,路径上传到阿里云是可以的

@RookieExaminer
Copy link
Author

暂时是模拟器测试的。
/storage/emulated/0/DCIM/com.pinet.cloth.android/1617246751183_100.JPG

@RookieExaminer
Copy link
Author

val compileSdkVersion = 30
val buildToolsVersion = "30.0.2"
val minSdkVersion = 23
val targetSdkVersion = 30

@forJrking
Copy link
Owner

原因找到了,我的问题。先按下面这样写

       val arrays = ArrayList<String>()
        Luban.with(this)                     
                .load(*arrays.toArray())         

@RookieExaminer
Copy link
Author

可以用了,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants