I have some colors that seem to come from a Delphi TColor variable (e.g 8388608, 128, 12632256). I need to convert those colors to their rgb values with a PHP script. How can this be done in PHP?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Delphi
TColortype is an integer whose bits contain the actual RGB values like this:Extracting RGB values:
You can filter out the parts by doing a bit-wise
ANDwith0xFF, while shifting the bits to the right.Delphi code:
PHP code:
Warning about system colors:
There are special colors which are derived from the system colors. (like button and window colors)
Those colors don’t actually have valid RGB values set. You can detect them by checking the first eight bits. If they are non-zero you have a special system color. You can also cast the color to an integer. If it is negative, it’s a system color.
In that case the R part contains the system color index.