获取特定像素的x,y位置

我遇到了一个问题,我得到了一个代码,它读取所有像素并获取像素的RGB颜色。 但在此之前,我将图片切成块,这样我也可以计算出更大的图像,而不会超出内存。 这是代码:

Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); try { decoder_image = BitmapRegionDecoder.newInstance(filePath, false); } catch (IOException e) { e.printStackTrace(); } try { boolean bool_pixel = true; final int width = decoder_image.getWidth(); final int height = decoder_image.getHeight(); // Divide the bitmap into 1100x1100 sized chunks and process it. // This makes sure that the app will not be "overloaded" int wSteps = (int) Math.ceil(width / 1100.0); int hSteps = (int) Math.ceil(height / 1100.0); Rect rect = new Rect(); for (int h = 0; h < hSteps; h++) { for (int w = 0; w < wSteps; w++) { int w2 = Math.min(width, (w + 1) * 1100); int h2 = Math.min(height, (h + 1) * 1100); rect.set(w * 1100, h * 1100, w2, h2); bitmap_image = decoder_image.decodeRegion(rect, null); try { int bWidth = bitmap_image.getWidth(); int bHeight = bitmap_image.getHeight(); int[] pixels = new int[bWidth * bHeight]; bitmap_image.getPixels(pixels, 0, bWidth, 0, 0, bWidth, bHeight); for (int y = 0; y < bHeight; y++) { for (int x = 0; x > 16) & 0xff; //bitwise shifting int G = (pixels[index] >> 8) & 0xff; int B = pixels[index] & 0xff; total++; if (R == 255){ //Save x,y position } if ((G > (R+2)) && (G > (B+2))) { counter++; } } } } finally { bitmap_image.recycle(); } } } } finally { decoder_image.recycle(); } 

这就像一个魅力。 有一些来自互联网的信息,我重新编写了我自己的代码。

但是现在我想要的是:当他检测到“完整”红色像素(255)时,他必须显示该像素的x,y位置。

我觉得这很容易做到,但因为我把图像切成了夹头,我得到了非常奇怪的x,y位置(我认为)。

我会快速解释为什么我想要这个:在图像中,它们是2个红色像素,那些2必须转换成矩形,但我没有得到好的x,y位置。

所以要明确问题:如何获得红色像素的x,y位置。

也许很容易,但不知怎的,我只是没有得到正确的位置,甚至没有关闭。 我在Photoshop中打开图像检查这一点,看看红色像素的x,y是什么,但我的应用程序给出了非常奇怪的坐标。

如果您需要更多信息或其他内容,请发表评论。

谢谢,Bigflow

坐标为rect.left + x和rect.top + y。 你有没试过这个?

x和y是图像中水平和垂直像素的位置,全局坐标取决于您所关注的坐标系的原点以及图像如何根据它移动。