开发者

How to load an image and resize it immediately to use later

开发者 https://www.devze.com 2023-04-01 00:29 出处:网络
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 l开发者_开发问答eads to OutOfMemoryError.

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 l开发者_开发问答eads to OutOfMemoryError. I tried smaller image is okay.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消