问题描述
我的工作对图像处理的应用程序。
我用BitmapFactory.de codeStream加载一个图像,当我preSS的按钮将图像传递到的setPixel,它会导致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 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?
推荐答案
使用 BitmapFactory.Options.inSampleSize
脱code较小的位图。
Use BitmapFactory.Options.inSampleSize
to decode a smaller bitmap.
公众诠释inSampleSize
自:API等级1
如果设定值> 1,要求德codeR二次采样原
图像,返回较小的图像以节省内存。样本量
对应于一个单一的任一维的像素数
像素在德codeD位图。例如, inSampleSize == 4
返回
图像即1/4原稿的宽度/高度,和1/16的
像素数。任何值< = 1是一样对待1.注意:
德codeR会尽量满足这一要求,但由此产生的位图可
有$ P $已要求pcisely什么不同的尺寸。
此外,2的幂往往更快/为德codeR兑现容易。
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.
这篇关于如何加载图像,并立即调整其大小以后使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!