C# Converting delphi TColor to color (Hex)

前端 未结 2 1066
终归单人心
终归单人心 2021-01-18 23:37

\"enter

These numbers are stored in the Database. They origionate from Delphi code. Al

2条回答
  •  没有蜡笔的小新
    2021-01-19 00:22

    It looks like the numbers are the base-10 representation of Delphi TColor values.

    Delphi itself seems to provide some helper functions (e.g. GetRValue) to extract the respective read, green and blue values. You have to write something similar in c# yourself.

    Having the values you can assemble them into a hex string.

    string.Format("#{0:X2}{1:X2}{2:X2}", redComponent, greenComponent, blueComponent);
    

    Simply converting the integer value to a hex-string, padded or not, will most likely not do the right thing.

    UPDATE as commenter James L. points out, the order of the components is actually different for/in delphi. To generate a TColor-like value the order must be:

    string.Format("#{0:X2}{1:X2}{2:X2}", blueComponent, greenComponent, redComponent);
    

提交回复
热议问题