Alpha + RGB & # 8594; ARGB?

In as3, is there a utility or function for converting RGB colors (e.g. 0xFF0000) and alpha values ​​(e.g. .5) to a 32-bit ARGB A value?

And from ARGB to RGB + alpha?

Some explanation: a bitmap can take an ARGB value in its constructor, but padding shapes in sprites usually takes RGB values. I would like the above utilities to ensure color matching.

+6
flash actionscript-3 rgb
source share
5 answers

var argb : int = (alpha<<24)|rgb;
var rgb : int = 0xFFFFFF & argb;
var alpha : int = (argb>>24)&0xFF;

+23
source share

A, R, G, B is the general format used by video cards to provide texture blending and transparency in the texture. Most systems use only 8 bits for R, G, and B to leave another 8 bits without a 32-bit word size, which is common for a PC.

 The mapping is: For Bits: 33222222 22221111 11111100 00000000 10987654 32109876 54321098 76543210 AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB 00000000 RRRRRRRR GGGGGGGG BBBBBBBB 

Something like that:

 private function toARGB(rgb:uint, newAlpha:uint):uint{ var argb:uint = 0; argb = (rgb); argb += (newAlpha<<24); return argb; } private function toRGB(argb:uint):uint{ var rgb:uint = 0; argb = (argb & 0xFFFFFF); return rgb; } 
+3
source share

If alpha can be represented by 8 bits, this is possible. Just map each area of ​​your 32-bit ARGB value to the corresponding variable, e.g.

0x0ABCDEF1

alpha - 0x0A

red - 0xBC

green - 0xDE

blue - 0xF1

0
source share
 private function combineARGB(a:uint,r:uint,g:uint,b:uint):uint { return ( (a << 24) | ( r << 16 ) | ( g << 8 ) | b ); } 
0
source share

I can't add anything else to the excellent answers above, but more simply, alpha values ​​are the last two digits in uint, for example

 //white var white:uint = 0xFFFFFF; //transparent white var transparent:uint = 0xFFFFFFFF; 

Scale as usual, 00 = 1 FF = 0.

Hope this helps

-2
source share

All Articles