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

可以扩展一个转Bitmap的压缩方法吗? #382

Open
Lovskey-Wei opened this issue Sep 28, 2020 · 1 comment
Open

可以扩展一个转Bitmap的压缩方法吗? #382

Lovskey-Wei opened this issue Sep 28, 2020 · 1 comment

Comments

@Lovskey-Wei
Copy link

作者你好,感谢分享。提Issues之前我已经把star点上了,嘻嘻~
请教下一个Bitmap在不写入文件的情况下怎么使用luban进行压缩。如果可以的话,希望给一下示例代码。

@forJrking
Copy link

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()

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