Skip to content Skip to sidebar Skip to footer

Convert RGB To X And Y In A Bitmap

I have a code which takes a bitmap and converts the X and Y coordinate to RGB: int pixel = bitmap.getPixel((int)x,(int) y); inRed = Color.red(pixel); inBlue = Color.blue(pixel); in

Solution 1:

To find the first pixel in a Bitmap with given Color:

int color = // your color
int x, y; // used for output
boolean found = false;
for (int ix = 0; ix < bitmap.getWidth(); ++ix) {
  for (int iy = 0; iy < bitmap.getHeight(); ++iy) {
    if (color == bitmap.getPixel(ix, iy) {
      found = true;
      x = ix;
      y = iy;
      break;
    }
  }
}

Post a Comment for "Convert RGB To X And Y In A Bitmap"