int color = image.getRGB(x,y);
然后我想单独购买的红,绿,蓝成分获得像素的颜色。怎么做?也许使用一些位掩码?
int green = color&0x00ff00;
显然不工作... :(
int color = image.getRGB(x,y);
然后我想单独购买的红,绿,蓝成分获得像素的颜色。怎么做?也许使用一些位掩码?
int green = color&0x00ff00;
显然不工作... :(
你忘了字节右移:
int green = (color & 0x00ff00) >> 8;
您可以使用Color
constructor并传递给定的整数和hasalpha=true
:
Color color = new Color(image.getRGB(x,y), true);
getRGB返回ty的颜色pe TYPE_INT_ARGB这意味着它有一个alpha通道。
为了让你可以使用颜色分量:
import android.graphics.Color;
int r = Color.red(intColor);
int g = Color.green(intColor);
int b = Color.blue(intColor);
int a = Color.alpha(intColor);
int value = image.getRGB(x,y);
R = (byte)(value & 0x000000FF);
G = (byte)((value & 0x0000FF00) >> 8);
B = (byte)((value & 0x00FF0000) >> 16);
A = (byte)((value & 0xFF000000) >> 24);
可能需要翻转过来,将R,A,或B。
并确保将两个字节右移红色! – ClosureCowboy 2010-12-05 19:10:58
还有一件事。 0x00ff是否等于0x00ff00? – Kamil 2010-12-05 19:13:30