Convert RGB to X and Y in a bitmap

三世轮回 提交于 2019-12-25 16:56:32

问题


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);
inGreen = Color.green(pixel);

How do I convert a given RGB and get the X and Y coordinate within the bitmap?


回答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;
    }
  }
}


来源:https://stackoverflow.com/questions/21692813/convert-rgb-to-x-and-y-in-a-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!