So I have an image saved in local storage. This image was taken using camera from the app itself. But the problem is the size of the image is about 3-4 MB. Is there anyway to compress this image before saving it to my local storage? Currently I am using CameraX to capture the picture. Thanks!
Asked
Active
Viewed 410 times
1 Answers
1
I have been using Tiny library and it works fine. It is easy to use and you can add configuration for compress image.
1.- Add dependency
implementation 'com.zxy.android:tiny:1.1.0'
2.- Initialization
Tiny.getInstance().init(this);
3.- Compress
Create options if you want to add some configuration
Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions();
Async
Tiny.getInstance().source("").asBitmap().withOptions(options).compress(new BitmapCallback() { @Override public void callback(boolean isSuccess, Bitmap bitmap, Throwable t) { //return the compressed bitmap object } });
Sync
BitmapResult result = Tiny.getInstance().source("").asBitmap().withOptions(options).compressSync();
For more details -> https://github.com/Sunzxyong/Tiny