可以扩展一个转Bitmap的压缩方法吗?
Lovskey-Wei opened this issue · 1 comments
Lovskey-Wei commented
作者你好,感谢分享。提Issues之前我已经把star点上了,嘻嘻~
请教下一个Bitmap在不写入文件的情况下怎么使用luban进行压缩。如果可以的话,希望给一下示例代码。
forJrking commented
https://github.com/forJrking/XLuban 分支 dev
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//compress方法是把一个位图写到一个OutputStream中,参数一是位图对象,二是格式,三是压缩的质量,四是输出流
newimage.compress(Bitmap.CompressFormat.JPEG, 100, baos);
//输出流转成输入流
InputStream inputimage = new ByteArrayInputStream(baos.toByteArray());
Luban.with(this)
.load(inputimage)
.filter { true }
.compressObserver {
onSuccess = { }
onStart = {}
onCompletion = {}
onError = { e, s -> }
}.launch()