Compressor
介绍:
一个安卓的图片压缩库。
运行效果:
使用说明:
Gradle
dependencies {
compile 'id.zelory:compressor:1.0.4'
}
Let's compress the image size!
压缩图片文件
compressedImageFile = Compressor.getDefault(this).compressToFile(actualImageFile);
把图片文件压缩成Bitmap
compressedImageBitmap = Compressor.getDefault(this).compressToBitmap(actualImageFile);
自定义压缩
compressedImage = new Compressor.Builder(this)
.setMaxWidth(640)
.setMaxHeight(480)
.setQuality(75)
.setCompressFormat(Bitmap.CompressFormat.WEBP)
.setDestinationDirectoryPath(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).getAbsolutePath())
.build()
.compressToFile(actualImage);
使用RxJava异步压缩
Compressor.getDefault(this)
.compressToFileAsObservable(actualImage)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<File>() {
@Override
public void call(File file) {
compressedImage = file;
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
showError(throwable.getMessage());
}
});
已下载
0