admin管理员组文章数量:1130349
I used the RGB function from Windows unit to generate random colors in VCL, and also used the TextOut to write text in bitmap.
Now I need to write that in FireMonkey for Android
Uses windows;
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=RGB(R, G, B);
label1.Font.Color:=c;
Is there an equivalent for these in FireMonkey?
I used the RGB function from Windows unit to generate random colors in VCL, and also used the TextOut to write text in bitmap.
Now I need to write that in FireMonkey for Android
Uses windows;
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=RGB(R, G, B);
label1.Font.Color:=c;
Is there an equivalent for these in FireMonkey?
Share Improve this question edited Dec 18, 2024 at 6:38 Abdul Aziz Barkat 21.7k7 gold badges54 silver badges83 bronze badges asked Dec 17, 2024 at 12:37 Mohsen DarrehshiriMohsen Darrehshiri 291 silver badge1 bronze badge 1 |2 Answers
Reset to default 6Firemonkey uses TAlphaColor colours. Use TAlphaColorRec from the System.UITypes unit to set the individual RGBA values of a colour, eg:
var C: TAlphaColorRec;
begin
C.A:=255; //Unless you also want random transparency!
C.R:=Random(256);
C.G:=Random(256);
C.B:=Random(256);
Label1.Font.Color:=C.Color;
end;
By the way, this won't actually change the font colour unless you also do the following:
Label1.StyledSettings:=Label1.StyledSettings-[TStyledSetting.FontColor];
When you change the font colour from the Object Inspector, it does that step for you. Without that step, you're telling Delphi to use the colour set in the style.
You might be looking for the function MakeColor in System.UIConsts.
Its defined like this:
function MakeColor(R, G, B: Byte; A: Byte = $FF): TAlphaColor;
So you can generate the color directly like this:
label1.Font.Color := MakeColor(Random(256),Random(256),Random(256));
Or to follow your example:
C: TAlphaColor;
begin
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=MakeColor(R, G, B);
label1.Font.Color:=c;
end;
I used the RGB function from Windows unit to generate random colors in VCL, and also used the TextOut to write text in bitmap.
Now I need to write that in FireMonkey for Android
Uses windows;
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=RGB(R, G, B);
label1.Font.Color:=c;
Is there an equivalent for these in FireMonkey?
I used the RGB function from Windows unit to generate random colors in VCL, and also used the TextOut to write text in bitmap.
Now I need to write that in FireMonkey for Android
Uses windows;
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=RGB(R, G, B);
label1.Font.Color:=c;
Is there an equivalent for these in FireMonkey?
Share Improve this question edited Dec 18, 2024 at 6:38 Abdul Aziz Barkat 21.7k7 gold badges54 silver badges83 bronze badges asked Dec 17, 2024 at 12:37 Mohsen DarrehshiriMohsen Darrehshiri 291 silver badge1 bronze badge 1-
As the
RGBfunction inWinApi.Windows.pasis provided as inline source, you may just copy that to a suitable location and change the result type toTColorRef. – Uwe Raabe Commented Dec 17, 2024 at 12:51
2 Answers
Reset to default 6Firemonkey uses TAlphaColor colours. Use TAlphaColorRec from the System.UITypes unit to set the individual RGBA values of a colour, eg:
var C: TAlphaColorRec;
begin
C.A:=255; //Unless you also want random transparency!
C.R:=Random(256);
C.G:=Random(256);
C.B:=Random(256);
Label1.Font.Color:=C.Color;
end;
By the way, this won't actually change the font colour unless you also do the following:
Label1.StyledSettings:=Label1.StyledSettings-[TStyledSetting.FontColor];
When you change the font colour from the Object Inspector, it does that step for you. Without that step, you're telling Delphi to use the colour set in the style.
You might be looking for the function MakeColor in System.UIConsts.
Its defined like this:
function MakeColor(R, G, B: Byte; A: Byte = $FF): TAlphaColor;
So you can generate the color directly like this:
label1.Font.Color := MakeColor(Random(256),Random(256),Random(256));
Or to follow your example:
C: TAlphaColor;
begin
R:=Random(256);
G:=Random(256);
B:=Random(256);
C:=MakeColor(R, G, B);
label1.Font.Color:=c;
end;
本文标签:
版权声明:本文标题:delphi - Is there an equivalent for RGB(Red, Green, Blue) from Windows Unit in FireMonkey? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1735996801a1376515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


RGBfunction inWinApi.Windows.pasis provided as inline source, you may just copy that to a suitable location and change the result type toTColorRef. – Uwe Raabe Commented Dec 17, 2024 at 12:51