Recent

Author Topic: How to use html colors in lazarus  (Read 5408 times)

Ericktux

  • Full Member
  • ***
  • Posts: 235
How to use html colors in lazarus
« on: May 12, 2018, 12:58:40 am »
good friends.
when using the colors of this website:
https://html-color-codes.info/

Lazarus shows me other colors, but if I invest them if they work.

Code: Pascal  [Select][+][-]
  1.  // #3A01DF  //online color code html
  2.  
  3.   form1.Color:=$3A01DF;  // show another color
  4.   form1.Color:=$DF013A;  // inverted if it works, why?


How can I use the web codes in lazarus?  :(

PD: attached image

josh

  • Hero Member
  • *****
  • Posts: 827
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

jamie

  • Hero Member
  • *****
  • Posts: 4452
Re: How to use html colors in lazarus
« Reply #2 on: May 12, 2018, 01:17:12 am »
Isn't that simply RGB color?

 MyColor := RGBToColor(StrToInt(HTMLColorSTring));

The StrToInt interprets the "$" at the start and knows to convert from HEX.
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 8406
Re: How to use html colors in lazarus
« Reply #3 on: May 12, 2018, 01:23:00 am »
Isn't that simply RGB color?
Almost... HTML has R and B interchanged: HTMLColor #RRGGBB, but TColor = $00BBGGRR

http://wiki.freepascal.org/Convert_color_to/from_HTML
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Ericktux

  • Full Member
  • ***
  • Posts: 235
Re: How to use html colors in lazarus
« Reply #4 on: May 12, 2018, 01:34:27 am »
thanks for your help friends, I'll prove it

jamie

  • Hero Member
  • *****
  • Posts: 4452
Re: How to use html colors in lazarus
« Reply #5 on: May 12, 2018, 03:15:01 am »
Code: Pascal  [Select][+][-]
  1. Function FlipColor(Const AValue:TColor):TColor;
  2. Type F = Record L,M,H,A:Byte; End;
  3. Var
  4.   J:Byte;
  5. Begin
  6.   Result := AValue;
  7.    J := F(Result).L; F(Result).L:= F(Result).H; F(Result).H:=J;
  8. end;
  9.  
  10. Function HtmlColorToColor(const S:String):TColor;
  11. Begin
  12.   Result := FlipColor(StrToInt(S));
  13. end;
  14. Function COlorToHtml(Const AValue:Tcolor):String;
  15. Begin
  16.   Result := '$'+IntTOHex(FlipColor(AValue),6);
  17. end;
  18.  

Something like that I guess...
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 10786
Re: How to use html colors in lazarus
« Reply #6 on: May 12, 2018, 06:43:04 am »
Needs to be packed record or even bitpacked record.

Ericktux

  • Full Member
  • ***
  • Posts: 235
Re: How to use html colors in lazarus
« Reply #7 on: May 12, 2018, 07:11:07 am »
thank you very much to all, at the moment it works like this:

We integrate the unit "ATStringProc_HtmlColor.pas" which you can obtain it from:
http://wiki.freepascal.org/Convert_color_to/from_HTML

Code: Pascal  [Select][+][-]
  1. Uses
  2. ATStringProc_HtmlColor,
  3.  
  4. var
  5.   colorcito: tcolor;
  6.   num1: integer;
  7.  
  8.   Form1.Color:=SHtmlColorToColor('#0040FF', num1, colorcito);  // work fine

………
ShtmlColorToColor returns color for lazarus $FF4000

at the moment it works well  :) :)

jamie

  • Hero Member
  • *****
  • Posts: 4452
Re: How to use html colors in lazarus
« Reply #8 on: May 12, 2018, 05:07:41 pm »
@Thaddy:

 The RECORD works fine, its single define which works out to a DWORD..

 Code was tested before posted..

The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 10786
Re: How to use html colors in lazarus
« Reply #9 on: May 12, 2018, 06:13:14 pm »
Jamie that is verification vs falsification and plain wrong: It happens to work on your system.

jamie

  • Hero Member
  • *****
  • Posts: 4452
Re: How to use html colors in lazarus
« Reply #10 on: May 12, 2018, 07:07:08 pm »
You make me laugh... are you ever wrong?

I also did an address test between the two using Delphi and they come out as 1 byte apart from
each other..
The only true wisdom is knowing you know nothing

voltag

  • Newbie
  • Posts: 3
Re: How to use html colors in lazarus
« Reply #11 on: April 18, 2021, 03:09:25 pm »
@jamie
Your code works.
I corrected your code a little.
But ATStringProc_HtmlColor its some monstrous.
Code: Pascal  [Select][+][-]
  1. uses Graphics;
  2. //...
  3. function FlipColor(Const AValue:TColor):TColor;
  4. type F = Record L,M,H,A:Byte; End;
  5. var
  6.   J:Byte;
  7. begin
  8.   //$F0 FB FF(TColor)
  9.   //#FF FB F0(HTML color)
  10.   Result := AValue;
  11.   J := F(Result).L;
  12.   F(Result).L:= F(Result).H;
  13.   F(Result).H:=J;
  14. end;
  15.  
  16. function HtmlColorToColor(S:String):TColor;
  17. var k: integer;
  18. begin
  19.   if S[1] = '#' then S[1]:= '$';
  20.   Result := FlipColor(StrToInt(S));
  21. end;
  22.  
  23. function ColorToHtml(Const AValue:Tcolor):String;
  24. begin
  25.   Result := '$'+IntTOHex(FlipColor(AValue),6);
  26. end;
  27.  
  28. //example
  29. myTColor:=HtmlColorToColor('#FFA0D2');
  30.  

It is possible that People served the parameter differently
 

jamie

  • Hero Member
  • *****
  • Posts: 4452
Re: How to use html colors in lazarus
« Reply #12 on: April 18, 2021, 03:36:45 pm »
you know there are already functions in the fpc lib for flipping things..

leToBe(yourValue)

and so on.
The only true wisdom is knowing you know nothing

lainz

  • Hero Member
  • *****
  • Posts: 4041
  • Leandro Diaz
Re: How to use html colors in lazarus
« Reply #13 on: April 18, 2021, 05:36:41 pm »
You can use BGRABitmap



Code: Pascal  [Select][+][-]
  1. uses
  2.   BGRABitmapTypes;
  3. ...
  4. var
  5.   p: TBGRAPixel;
  6.   c: TColor;
  7. ...
  8. p.fromString('#e1e1e1');
  9. c := p;
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

winni

  • Hero Member
  • *****
  • Posts: 2331
Re: How to use html colors in lazarus
« Reply #14 on: April 18, 2021, 07:15:41 pm »
Hi!

Also BGRABitmap:

Code: Pascal  [Select][+][-]
  1. uses ...., BGRAbitmap, BGRADefaultBitmap;
  2. ....
  3. var  tmp : TBGRAbitmap;
  4. ....
  5. tmp.swapRedBlue;
  6. ...
  7.  

Winni

 

TinyPortal © 2005-2018