转换RGB到X和Y中一个位图 [英] Convert RGB to X and Y in a bitmap

查看:321
本文介绍了转换RGB到X和Y中一个位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个code这需要一个位图和转换的X和Y坐标为RGB

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);

我要如何转换成一个给定的RGB,并得到X和Y位图中的坐标?

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

推荐答案

要与给定的颜色找到一个位图的第一个像素:

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

这篇关于转换RGB到X和Y中一个位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆