将delphi TColor转换为PHP。

时间:2021-08-19 17:34:24

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?

我有一些颜色似乎来自于Delphi TColor变量(e。g 8388608,128,12632256)。我需要用一个PHP脚本将这些颜色转换为它们的rgb值。如何在PHP中实现?

1 个解决方案

#1


8  

The Delphi TColor type is an integer whose bits contain the actual RGB values like this:

Delphi TColor类型是一个整数,其位包含实际的RGB值如下:

ssBBGGRR

Extracting RGB values:

提取RGB值:

You can filter out the parts by doing a bit-wise AND with 0xFF, while shifting the bits to the right.

您可以通过做一个bit-wise和0xFF来过滤掉这些部分,同时将位移到右边。

Delphi code:

Delphi代码:

R := Color and $FF;
G := (Color shr 8) and $FF;
B := (Color shr 16) and $FF; 

PHP code:

PHP代码:

R = Color & 0xFF;
G = (Color >> 8) & 0xFF;
B = (Color >> 16) & 0xFF; 

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.

这些颜色实际上并没有有效的RGB值,您可以通过检查前8位来检测它们。如果它们是非零的,你就有一个特殊的系统颜色。您还可以将颜色转换为整数。如果它是负的,它是一个系统颜色。

In that case the R part contains the system color index.

在这种情况下,R部分包含系统颜色索引。

#1


8  

The Delphi TColor type is an integer whose bits contain the actual RGB values like this:

Delphi TColor类型是一个整数,其位包含实际的RGB值如下:

ssBBGGRR

Extracting RGB values:

提取RGB值:

You can filter out the parts by doing a bit-wise AND with 0xFF, while shifting the bits to the right.

您可以通过做一个bit-wise和0xFF来过滤掉这些部分,同时将位移到右边。

Delphi code:

Delphi代码:

R := Color and $FF;
G := (Color shr 8) and $FF;
B := (Color shr 16) and $FF; 

PHP code:

PHP代码:

R = Color & 0xFF;
G = (Color >> 8) & 0xFF;
B = (Color >> 16) & 0xFF; 

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.

这些颜色实际上并没有有效的RGB值,您可以通过检查前8位来检测它们。如果它们是非零的,你就有一个特殊的系统颜色。您还可以将颜色转换为整数。如果它是负的,它是一个系统颜色。

In that case the R part contains the system color index.

在这种情况下,R部分包含系统颜色索引。