0

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!

ADM
  • 20,406
  • 11
  • 52
  • 83
Prototype7
  • 31
  • 4

1 Answers1

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
rguzman
  • 319
  • 3
  • 8