The following is my way to get eh RGB color and change the color in temp (Bitmap) when the color in bitmap (another Bitmap) is green. But the performance is quite bad and the time used around 20 secs or more. Is there any ways for me to improve it ? Thank you very much.
//get the green color of each pixel
color = new int[bitmap.getWidth()][bitmap.getHeight()];
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
color[x][y] = temp.getPixel(x, y);
if (bitmap.getPixel(x, y) == Color.GREEN) {
color[x][y] = temp.getPixel(x, y);
float[] hsv = new float[3];
Color.RGBToHSV(Color.red(color[x][y]), Color.green(color[x][y]), Color.blue(color[x][y]), hsv);
hsv[0] = 360;
color[x][y] = Color.HSVToColor(hsv);
}
temp.setPixel(x, y, color[x][y]);
}
}
imageView.setImageBitmap(temp);
Update:
intArray = new int[bitmap.getWidth()*bitmap.getHeight()];
bitmap.getPixels(intArray,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
int[] tempArray = new int[bitmap.getWidth()*bitmap.getHeight()];
temp.getPixels(tempArray,0,temp.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
//get the color of each pixel
color = new int[bitmap.getWidth()][bitmap.getHeight()];
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
if (intArray[x + y * bitmap.getWidth()] == Color.BLUE) {
float[] hsv = new float[3];
Color.RGBToHSV(Color.red(tempArray[x + y * bitmap.getWidth()]), Color.green(tempArray[x + y * bitmap.getWidth()]), Color.blue(tempArray[x + y * bitmap.getWidth()]), hsv);
hsv[0] = 360;
tempArray[x + y * bitmap.getWidth()] = Color.HSVToColor(hsv);
}
}
}
temp.setPixels(tempArray,0,temp.getWidth(),0,0,temp.getWidth(),temp.getHeight());
imageView.setImageBitmap(temp);