所以我有一个图像保存在本地存储中。该图像是使用应用本身的相机拍摄的。但是问题是图像的大小约为3-4 MB。无论如何,在将其保存到本地存储之前是否要对其进行压缩?目前,我正在使用CameraX捕获图片。谢谢!
答案 0 :(得分:1)
我一直在使用Tiny库,它运行正常。它易于使用,您可以添加用于压缩图像的配置。
1.-添加依赖项
implementation 'com.zxy.android:tiny:1.1.0'
2.-初始化
Tiny.getInstance().init(this);
3.-压缩
如果要添加一些配置,请创建选项
Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions();
异步
Tiny.getInstance().source("").asBitmap().withOptions(options).compress(new BitmapCallback() {
@Override
public void callback(boolean isSuccess, Bitmap bitmap, Throwable t) {
//return the compressed bitmap object
}
});
同步
BitmapResult result = Tiny.getInstance().source("").asBitmap().withOptions(options).compressSync();
有关更多详细信息-> https://github.com/Sunzxyong/Tiny