0
我有像0x8833aacc
簡單的顏色INT如果我現在用Color.colorToHSV
創建它的HSV值,
然後用Color.HSVToColor
得到INT回來,這是細微的差別!
the red value decreases by 1
android顏色類 - 奇怪的行爲,內部舍入錯誤?
但它確實不這樣每次,例如當使用0x8830aacc
各種確定,爲什麼?
我的示例代碼顯示此:
final float[] current_hsv = new float[3];
float current_alpha = 1.0f;
private int GetColor()
{
return Color.HSVToColor((int)(current_alpha * 255.0f), current_hsv);
}
private void SetColor(int color)
{
Color.colorToHSV(color, current_hsv);
current_alpha = (float)Color.alpha(color)/255.0f;
}
private void Test()
{
int color = 0x8833aacc;
SetColor(color);
int g = GetColor();
//convert to hex, you'll see the red value decreased by 1!!!
Log.i("Test", "color: " + String.format("%08x", color) + " got color: " + String.format("%08x", g));
}
如何解決呢?