3

Can someone suggest me a library that can do simplest operations like scale, crop, rotate without loading image fully into memory?

The situation: I need to scale image down from a very large size, but the scaled down image is still too large to be allocated in memory (if we use standard android tools). Since I only need to upload scaled down version, I thought of scaling it through native library and upload it through FileInputStream.

I've tried to use ImageMagic and it does the job, but performance is very poor (maybe there is a way to speed things up?)

Alex Orlov
  • 18,077
  • 7
  • 55
  • 44

2 Answers2

1

Might want to check out OpenCV for Android

Osiris
  • 4,195
  • 2
  • 22
  • 52
0

You can use the original Android Bitmap functionality by pulling the image into memory but allowing Android to sample the image before it is loaded.

For example:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap myBitmap = BitmapFactory.decodeStream(inputstream,null,options);

This will load your bitmap into memory with half the memory footprint of the full image. You can experiment with changing the inSampleSize to get a good fit for your application.

You can also calculate the sample size on the fly, if you know the final image size you are aiming for, you can get the current file size of the image before you load it into memory and calculate the sample size using the equation inSampleSize = OriginalSize/RequiredSize. Though sample size is best used when it is a power of 2, so you can make adjustments for this.

Edit: A great example here https://stackoverflow.com/a/823966/637545

Community
  • 1
  • 1
biddulph.r
  • 5,226
  • 3
  • 32
  • 47