【问题标题】:android Bitmap getPixelandroid 位图 getPixel
【发布时间】:2012-03-27 15:53:13
【问题描述】:

我需要获取一个像素的颜色,以便将其与我的 color.xml 文件中的颜色进行比较,但是所有值都是负数,并且这种比较总是会返回错误的结果。如何获得正确的颜色值?这种颜色可以是透明的。我读过this,但我需要一个答案,而不是理论的链接。

bmp.getPixel(n.x, n.y) 在我期望返回颜色 #00FFFFFF 的正确值时返回零

谢谢

【问题讨论】:

  • 尚未在 android 中执行此操作,但不是 Color c = bmp.getPixel(..., ...);可用的? => c.R, c.G, c.B.将是 rgb 值。

标签: android colors bitmap getpixel


【解决方案1】:

你可以这样做:

int pixel = Color.RED; //bmp.getPixel(n.x, n.y);
int a = Color.alpha(pixel);
int r = Color.red(pixel);
int g = Color.green(pixel);
int b = Color.blue(pixel);

String color = String.format("#%02X%02X%02X%02X", a, r, g, b); //#FFFF0000 for RED color

但您可以使用 bmp.getPixel(...) 方法代替 Color.RED

希望有帮助

最好的问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    相关资源
    最近更新 更多