前言:http://www.cnblogs.com/studypanp/p/5002953.html 獲取的顏色值
前面獲取到一個像素點的顏色值后(十六進制),比如說(黃色):FFD1C04C(共八位),我自認為前面兩位代表透明度,其它順序為R-G-B, 沒想到順序是G-B-R
下面為從十六進制解析RGB的函數:(這里是把FF當成了R)
function TForm2.HexColorToRGB(s: string): string; // 傳進來的是顏色值
var
i: Integer;
R,G,B: Byte;
begin
i := s.ToInteger;
R := i and $FF;
G := (i shr 8) and $FF;
B := (i shr 16) and $FF;
// Result := Format('%.2x,%.2x,%.2x',[R,G,B]); // 返回十六進制的RGB
Result := Format('%.2d,%.2d,%.2d',[R,G,B]); // 返回RGB: 76,192,209
end;
我在畫圖上的顏色編輯器上輸入R:76, G:192,B:209,畫布上面顯示的是藍色,我又郁悶...
后來我把這三個數打錯順序輸入,結果發現192,209,76才是原來的顏色,位數不是按RGB的順序,而是按BRG的順序,郁悶死我了
至少我在XE中結果是這樣的。
function TForm2.HexColorToRGB(s: string): string; // 傳進來的是顏色值
var
i: Integer;
R,G,B: Byte;
begin
i := s.ToInteger;
B := i and $FF;
R := (i shr 8) and $FF;
G := (i shr 16) and $FF;
// Result := Format('%.2x,%.2x,%.2x',[R,G,B]); // 返回十六進制的RGB
Result := Format('%.2d,%.2d,%.2d',[R,G,B]); // 返回RGB 192,209,76
end;
所以需要把原來函數的順序變一下。
