Delphi gets the RGB color value

Source: Internet
Author: User

Preface: Http://www.cnblogs.com/studypanp/p/5002953.html Gets the color value

Before getting to a pixel color value (hex), for example (yellow): ffd1c04c (total eight bits), I think the front two bits represent the transparency, the other order is r-g-b, didn't think the order is G-b-r

The following is a function that resolves RGB from hex: (here is the FF as R)

function Tform2.hexcolortorgb (s:string): string;    The color value var i:integer   is passed in.  R,g,b:byte;begin I: = S.tointeger;  R: = i and $FF;  G: = (i shr 8) and $FF; B: = (i shr) and $FF;//Result: = Format ('%.2x,%.2x,%.2x ', [r,g,b]);            Returns the hexadecimal RGB Result: = Format ('%.2d,%.2d,%.2d ', [r,g,b]);      return to Rgb:76,192,209end;

I entered r:76 on the Paint color editor, g:192,b:209, the canvas above is blue, I am depressed ...

Later I put the three numbers in the wrong order, the results found that 192,209,76 is the original color, the number of digits is not in accordance with the order of RGB, but in accordance with the order of BRG, depressed my death

At least that's what I did in XE.

function Tform2.hexcolortorgb (s:string): string;    The color value Vari:integer  is passed in. R,g,b:byte;begini: = S.tointeger; B: = i and $FF; R: = (i shr 8) and $FF; G: = (i shr) and $FF;//result: = Format ('%.2x,%.2x,%.2x ', [r,g,b]);    Returns the hexadecimal rgbresult: = Format ('%.2d,%.2d,%.2d ', [r,g,b]);    Returns the RGB 192,209,76end;

So we need to change the order of the original function.

Delphi gets the RGB color value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.