0

I need to scale a large (8+ megapixel) image taken with the camera app, down to about 3 megapixels. Unfortunately, I cannot use the beloved Bitmap.createScaledBitmap() function since in order to load the 8M image Android needs to allocate about 32 megabytes of (continuous) RAM memory. This immediately throws an OutOfMemoryError.

People suggested I use native code to do the scale, but this is too much work for this project. Does someone have any other suggestions?

I wonder if I can somehow use RenderScript to achieve this result, although I'm very doubtful.

Thanks!

Update: Implementation of Bitmap.createScaledBitmap().

stojanman
  • 325
  • 3
  • 15
  • Can't the camera app do this for you? – wvdz Nov 12 '13 at 22:21
  • Did you read this? http://developer.android.com/training/camera/photobasics.html#TaskScalePhoto – wvdz Nov 12 '13 at 22:24
  • @popovitsj: Yes, the problem is loading the bitmap. `inSampleSize` only subsamples the image, does not do an actual _scale_. I need a true, antialiased, scaled image like `Bitmap.createScaledBitmap()` creates. – stojanman Nov 12 '13 at 22:27
  • @popovitsj: No, can't send an intent which specifies resolution or other similar parameters. :( – stojanman Nov 12 '13 at 22:27
  • I don't understand the difference between subsampling and downscaling – wvdz Nov 12 '13 at 22:34
  • @popovitsj: As I said, `inSampleSize` does not antialias the images. It is not a proper scaling algorithm. It just "skips" so many pixels (which would not affect the final result). That's why it uses powers of 2, since you only want to save vast amounts of memory when using `inSampleSize`. If I were to use it, I'd go with `inSampleSize` of 2, which amounts to 16 MB of loaded bitmap, which is still a problem. – stojanman Nov 12 '13 at 22:44
  • 2
    `android:largeHeap="true"` – dcow Nov 12 '13 at 23:19
  • @DavidCowden Will try, although it's only a temporary fix. – stojanman Nov 13 '13 at 00:09
  • 1
    If you use RGB565 colorspace, 32 MBytes become 16. – Alex Cohn Nov 13 '13 at 04:48
  • 1
    If you subsample by factor of 2, it's both width and height, therefore the result will be 2 Megapixel from the 8 megapixel original. – Alex Cohn Nov 13 '13 at 04:55

0 Answers0