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