Big*_*low 1 memory android colors bitmap
如果我用我的三星galaxy s2拍照,图片是3264 x 2448像素.我想对它使用颜色范围检查,但它不起作用.
但是,如果我将图片缩小,例如2500 x 2500(像素更少),那么它确实有效.但我希望使用星系s2(3264 x 2448)的图片大小.我认为这是一个记忆问题?我不完全知道限制是什么.但他们是另一种"绕过"这个问题的方法吗?
这是一段代码,我现在是怎么做的:
bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.four_colors);
int width = bmp.getWidth();
int height = bmp.getHeight();
int[] pixels = new int[width * height];
bmp.getPixels(pixels, 0, width, 0, 0, width, height);
for (int y = 0; y < height; y++){
for (int x = 0; x < width; x++){
int index = y * width + x;
int R = (pixels[index] >> 16) & 0xff; //bitwise shifting
int G = (pixels[index] >> 8) & 0xff;
int B = pixels[index] & 0xff;
total++;
if ((G > R)&&(G > B)){
counter++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它崩溃是因为图片是大而小的图片工作.那么他们的东西是否"绕过"这个问题呢?而不是使用较小的图像:)
我试了一些其他的东西,没有成功,我试着解释我试过的东西.
我试图将图像"剪切"成两个,然后将其单独扫描(不起作用).
我试图只扫描它的一半(1632 x 1224)然后旋转图像(180度)并再次扫描,但这也没有用.
在玩大量图像时,您应该使用BitmapRegionDecoder以块的形式处理它.
编辑 - 现在举一个简单的例子:
try {
// Processes file in res/raw/huge.jpg or png
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(getResources().openRawResource(R.raw.huge), false);
try {
final int width = decoder.getWidth();
final int height = decoder.getHeight();
// Divide the bitmap into 1024x768 sized chunks and process it.
int wSteps = (int) Math.ceil(width / 1024.0);
int hSteps = (int) Math.ceil(height / 768.0);
Rect rect = new Rect();
long total = 0L, counter = 0L;
for (int h = 0; h < hSteps; h++) {
for (int w = 0; w < wSteps; w++) {
int w2 = Math.min(width, (w + 1) * 1024);
int h2 = Math.min(height, (h + 1) * 768);
rect.set(w * 1024, h * 768, w2, h2);
Bitmap bitmap = decoder.decodeRegion(rect, null);
try {
int bWidth = bitmap.getWidth();
int bHeight = bitmap.getHeight();
int[] pixels = new int[bWidth * bHeight];
bitmap.getPixels(pixels, 0, bWidth, 0, 0, bWidth, bHeight);
for (int y = 0; y < bHeight; y++){
for (int x = 0; x < bWidth; x++){
int index = y * bWidth + x;
int R = (pixels[index] >> 16) & 0xff; //bitwise shifting
int G = (pixels[index] >> 8) & 0xff;
int B = pixels[index] & 0xff;
total++;
if ((G > R)&&(G > B)){
counter++;
}
}
}
} finally {
bitmap.recycle();
}
}
}
} finally {
decoder.recycle();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2172 次 |
| 最近记录: |