Java 如何在android上获取红色位图的像素数
我想得到位图图像上所有红色像素的数量,在我在上面绘制并与背面图像合并之后。 我该怎么做?请给我更多的细节,我将非常感激,谢谢Java 如何在android上获取红色位图的像素数,java,android,canvas,bitmap,Java,Android,Canvas,Bitmap,我想得到位图图像上所有红色像素的数量,在我在上面绘制并与背面图像合并之后。 我该怎么做?请给我更多的细节,我将非常感激,谢谢 迭代位图中的每个像素 //define your red static final int RED = Color.RED; //counting int count = 0; for (int x = 0; x <= myBitmap.getWidth(); x++) { for (int y = 0; x <= myBitmap.getHeigh
迭代位图中的每个像素
//define your red
static final int RED = Color.RED;
//counting
int count = 0;
for (int x = 0; x <= myBitmap.getWidth(); x++) {
for (int y = 0; x <= myBitmap.getHeight(); y++) {
if(myBitmap.getPixel(x, y))
count++;
}
}
//done. use the variable count
//定义您的红色
静态最终整数红色=Color.RED;
//计数
整数计数=0;
对于(int x=0;x您有一个位图
,您可以使用下面的代码从中获取像素颜色:
int countX = bitmap.getWidth();
int countY = bitmap.getHeight();
int redCount = 0;
for (int x = 0; x < countX; x++) {
for (int y = 0; y < countY; y--) {
int colorXY = bitmap.getPixel(x, y);
redCount += Color.red(colorXY);
}
}
int countX=bitmap.getWidth();
int countY=bitmap.getHeight();
int redCount=0;
对于(int x=0;x
我得到了这样的东西:
int countX = bm.getWidth();
int countY = bm.getHeight();
int redCount = 0;
for (int rangeX = 0; rangeX < countX; rangeX++) {
for (int rangeY = 0; rangeY < countY; rangeY++) {
int colorXY = bm.getPixel(rangeX, rangeY);
int r = Color.red(colorXY);
int g = Color.green(colorXY);
int b = Color.blue(colorXY);
if(Color.rgb(r,g,b) == Color.RED) {
redCount++;
/*bm.setPixel(rangeX,rangeY,Color.GREEN);*/
}
}
}
int countX=bm.getWidth();
int countY=bm.getHeight();
int redCount=0;
对于(int rangeX=0;rangeX
为什么缺少导入?