Just starting out, and not confident to post this in the Bug Reports.
When I use RGB(255, 0, 0) in a function that needs a color (like SetGadgetColor) on the screen, it is red as expected.
But when using a Hex color of $FF0000, blue is shown on the screen. (And $0000FF is red.)
I regularly use hex colour codes in paint programs and in local html files and have not seen this reversal before.
I can just use the RGB function, but the behaviour is unexpected, and I wonder if anyone has encountered it before. (And if I did use Hex codes, should I worry that users will not be seeing what I intended?)
Hex Color values reverse the Red and Blue
Re: Hex Color values reverse the Red and Blue
Inside your program, no one will see how you wrote the color code. You already know about this problem and always set the color correctly. If you read the color from an ini file, simply flip it when reading:
ColorValidate()
ColorValidate()
Code: Select all
Procedure RGBtoBGR(c)
; ProcedureReturn RGB(Blue(c), Green(c), Red(c))
ProcedureReturn ((c & $00FF00) | ((c & $0000FF) << 16) | ((c & $FF0000) >> 16))
EndProcedureRe: Hex Color values reverse the Red and Blue
The behaviour of RGB() or RGBA are never unexpected
Your Problem is, thet PB uses (A)BGR internally and not RGB(A)
So if you using direct hex values the format is ABGR.
Your Problem is, thet PB uses (A)BGR internally and not RGB(A)
Code: Select all
Debug Hex(RGBA(1, 2, 3, 4), #PB_Long)Re: Hex Color values reverse the Red and Blue
Thank you, I have also now found the Color Table topic in the Help, which confirms this.infratec wrote: Sun Nov 09, 2025 10:58 am Your Problem is, thet PB uses (A)BGR internally and not RGB(A)
I made a wrong assumption, and appreciate the answers.submit the color value as whole value - but then the red and blue parts must be swapped, i.e. the color submitted in the BGR format.
Re: Hex Color values reverse the Red and Blue
Yes, this is a solution, but why is it like this and not like all other programs, which have the same sequence? It would be more logical to use rgba in hex as well.AZJIO wrote: Sun Nov 09, 2025 10:48 am Inside your program, no one will see how you wrote the color code. You already know about this problem and always set the color correctly. If you read the color from an ini file, simply flip it when reading:
ColorValidate()Code: Select all
Procedure RGBtoBGR(c) ; ProcedureReturn RGB(Blue(c), Green(c), Red(c)) ProcedureReturn ((c & $00FF00) | ((c & $0000FF) << 16) | ((c & $FF0000) >> 16)) EndProcedure
Re: Hex Color values reverse the Red and Blue
Legacy stuff. Would cause a ton of problems if changed now.
Re: Hex Color values reverse the Red and Blue
When formatting a color for a human to read (HTML, CSS, image editors, some config files) they're usually written in intuitive RRGGBB order, often prefixed with "#"
But in memory and in low level programming, they're usually BBGGRR prefixed with 0x (or "$" in PB syntax)
I assume PB made this choice early to match OS APIs (at least Windows) and it's been that way ever since. (Internally! You can display it to the end user however you want)
For example: Windows defines Red as 0x0000FF
https://learn.microsoft.com/en-us/windo ... i/colorref
But in memory and in low level programming, they're usually BBGGRR prefixed with 0x (or "$" in PB syntax)
I assume PB made this choice early to match OS APIs (at least Windows) and it's been that way ever since. (Internally! You can display it to the end user however you want)
For example: Windows defines Red as 0x0000FF
https://learn.microsoft.com/en-us/windo ... i/colorref



