How do you calculate pixel32 color?


(ReiKGT) #1

I’m trying to add borders to text by directly manipulating the _buffer in a Text object. It’s working out well enough. So far though I can only add border to text if I’ve already hardcoded in a color. I’m curious how 0x00000000 becomes 4278190080 when you set a pixel to black. What calculation do I have to perform to turn non alpha hex color into a 1 alpha pixel32 color?

I don’t need any info for any other alpha values. It’s not like I’m going to ever need semi-transparent bordered text.


(JP Mortiboys) #2

You need to see it in hexadecimal… basically there’s two (hex) digits in front of the normal rgb digits which indicate alpha.

So normal rgb red is 0xFF0000, green is 0x00FF00, green is 0x0000FF. With a full (100% opaque) alpha component this becomes red: 0xFFFF0000, green: 0xFF00FF00, blue: 0xFF0000FF.

If you do want semi-transparency, that leading FF becomes, say 7F (127 in hex). So semi-transparent blue would be 0x7F0000FF.


(ReiKGT) #3

Yeah I understand that but the problem is that it doesn’t work.

If you setPixel32 0xFF000000 you will set the pixel to pure black, no alpha. I understand why. BUT if you use getPixel32 to retrieve the color value you will get 4278190080 instead. Which makes no sense to me.


(JP Mortiboys) #4

https://duckduckgo.com/?q=4278190080+in+hex


(ReiKGT) #5

Alright this will help. Thanks.


(Zachary Lewis) #6

This might be more informative.


(Jacob Albano) #7

You can also pass a radix value to the toString() method on a numeric variable to display it as hex:

var color:uint = _buffer.getPixel32(x, y);
trace("0x" + color.toString(16)); // hexadecimal is base 16