zoukankan      html  css  js  c++  java
  • RGB(16进制)_转_TColor

    ZC:内存中 COLORREF就是一个DWORD(从定义"COLORREF = DWORD;"就可以看出来),但是 具体的byte R/G/B 的位置是怎么方式的?

    ZC:Windows.pas 中 函数 function RGB(r, g, b: Byte): COLORREF;

    1、

    function RGBToColor(R,G,B: byte): TColor;
    begin
      Result := B Shl 16 or G  shl 8 or R;
    end;

    2、TColor 转 R/G/B

    procedure ExtractRGB(const Color: Graphics.TColor; out Red, Green, Blue: Byte);
    var
      RGB: Windows.TColorRef; // RGB equivalent of given Colour
    begin
      RGB := Graphics.ColorToRGB(Color);  // ensures system Colours are converted
      Red := Windows.GetRValue(RGB);
      Green := Windows.GetGValue(RGB);
      Blue := Windows.GetBValue(RGB);
    end;

    3、转的:

    // 1.RGB转换为Tcolor
    
    function RGBToColor(R,G,B: byte): Tcolor;
    begin
      Result := B Shl 16 or G  shl 8 or R;
    end;
     
    
    // 2.Tcolor转换为RGB
     
    proceudre Tform1.Button1Clink(Sender: Tobject);
    var
      Color: TColor;
      R, G, B: integer;
    begin
      Color := ClBlack;
      R := Color and $FF;
      G := (Color and $FF00) shr 8;
      B := (Color and $FF0000) shr 16;
    end;

    4、

    5、

  • 相关阅读:
    10.28
    10.29
    11.05周四
    数据库增删改查
    11.03Tuesday
    11.10
    连接数据库
    10.30
    11.04周三
    10.27
  • 原文地址:https://www.cnblogs.com/CodeSkill/p/5834079.html
Copyright © 2011-2022 走看看