Page 1 of 1

ReadBrushPixel usage

Posted: Sun Mar 23, 2025 12:47 pm
by amyren
How does the result from ReadBrushPixel and ReadPixel work?
The docs say it will give the result in RGB format, but the output I get does not look like that.
Example black color returns simply 0. white 16777215, 16701184 - yellow, 14423100 - red,
3978097 - green etc.
How to get these into a format where I can read the value 0-255 for each of R, G and B?

Re: ReadBrushPixel usage

Posted: Sun Mar 23, 2025 1:43 pm
by Flinx
These numbers are the RGB values. For example, take a hexadecimal look at your white value:
DebugPrint(HexStr(16777215)) returns $FFFFFF.
Now you could extract the green value, for example, by dividing by 256, taking the integer part (that removes blue), dividing by 256 again, taking the remainder (that removes red) and multiplying by 256 again.
Another way would be to use the logical operators and the bitwise operators.
But Hollywood makes it easier for you and has the functions Red(), Green() and Blue().

Code: Select all

z=16777215
DebugPrint(HexStr(z))
DebugPrint(Frac(Int(z/256)/256)*256)
DebugPrint((z And $00FF00)>>8)
DebugPrint(Green(z))

Re: ReadBrushPixel usage

Posted: Sun Mar 23, 2025 6:49 pm
by amyren
Thanks for explaining

Re: ReadBrushPixel usage

Posted: Mon Mar 24, 2025 10:35 am
by Flinx
But I made a mistake: The fourth line must, of course, only use bitwise operators, no logical.

Code: Select all

DebugPrint((z & $00FF00)>>8)