0

I am working on an app for image processing. I use BitmapFactory.decodeStream to load an image, when I press the button to pass the image to setPixel, it leads to OutOfMemoryError. I tried smaller image is okay.

Anyway to load a big image and immediately save it in Bitmap with a smaller size?

Booker
  • 1
  • 1
  • 1

1 Answers1

2

Use BitmapFactory.Options.inSampleSize to decode a smaller bitmap.

public int inSampleSize

Since: API Level 1

If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value <= 1 is treated the same as 1. Note: the decoder will try to fulfill this request, but the resulting bitmap may have different dimensions that precisely what has been requested. Also, powers of 2 are often faster/easier for the decoder to honor.

Michael
  • 53,859
  • 22
  • 133
  • 139