Comments (10)
如下
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()
from kluban.
val arrays = ArrayList<File>()
数组是 string类型的文件路径 是否可以?
from kluban.
因为我使用的时候传入string类型的文件路径 list,报错,
from kluban.
File,Uri,InputStream,String,和以上数据 单个、数组、集合 都支持的 具体报错显示什么错误
from kluban.
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)
from kluban.
我传入的是string 类型的图片路径 list ,路径上传到阿里云是可以的
from kluban.
暂时是模拟器测试的。
/storage/emulated/0/DCIM/com.pinet.cloth.android/1617246751183_100.JPG
from kluban.
val compileSdkVersion = 30
val buildToolsVersion = "30.0.2"
val minSdkVersion = 23
val targetSdkVersion = 30
from kluban.
原因找到了,我的问题。先按下面这样写
val arrays = ArrayList<String>()
Luban.with(this)
.load(*arrays.toArray())
from kluban.
可以用了,感谢
from kluban.
Related Issues (20)
- rename 返回的是整个路径不是文件名 HOT 2
- 会出现压缩后反而更大的情况,文件有后缀的时候输出文件还会再加一次后缀。 HOT 6
- load()传入List<Uri> 返回为空 HOT 1
- heic图片压缩后旋转 HOT 4
- 如何避免重复压缩同一张图片 HOT 1
- 大神 java版本调用 如何在compressObserver中获取压缩后的File? 对kotlin不太熟悉 可以出个java版本的demo吗
- 压缩图片抛InvalidMarkException HOT 3
- 选择不并行(useConcurrent为false)时,onSuccess list为空 HOT 1
- 上传部分图片时会抛出异常:InvalidMarkException: Mark has been invalidated, pos: 1423393 markLimit: 5242880 HOT 2
- 有一些jpg图片会有格式识别不出来的情况
- 编译失败, 2 files found with path 'META-INF/library_release.kotlin_module'. HOT 1
- 能解答一下,这不部分的计算是根据啥么?
- asyncRun这段代码的协程handler里面应该回调error吧,不然报错了,也没有回调,就卡在那了 HOT 1
- load(bitmap) 输出只有Bitmap.CompressFormat.JPEG格式,后面checker 头的时候也会把png图片也当成JPEG
- 既然都使用协程了为什么不能提供suspend方法?
- 压缩超长图片,特别耗时的问题
- 16K图片压缩问题 HOT 4
- 建议加一下宽高限制
- InputStream mark问题 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kluban.