Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't the BitmapData transparent?

    var subimage = new Bitmap();
    subimage.bitmapData = new BitmapData(25, 25, true, 0);
    addChild(subimage);

From everything I've read, this should be transparent. I'm seeing a big black square. What could cause that?

like image 283
thedayturns Avatar asked Aug 25 '12 11:08

thedayturns


2 Answers

use this

new BitmapData(25, 25, true, 0x00000000);

instead of

new BitmapData(25, 25, true, 0);

0xFF000000 is black(0x000000) with alpha equal to 1

0x00000000 is black(0x000000) with alpha equal to 0

Here is a nice explanation how colors & alpha work: http://myflex.wordpress.com/2007/09/07/about-hex-color-codes-in-flex-as3/

//EDIT:

Dennis Krøger and strille are right, 0x00000000 == 0. Looks like the problem is somewhere else, not in the code you pasted in.

like image 137
sanchez Avatar answered Sep 22 '22 12:09

sanchez


ActionScript uses a 32-bit hexadecimal numbers to represent color values with transparency. ARGB colors as 32 bit variables are specified by 4 groups of 8 bits each / or 2 hex each:

In binary: AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB

In hex: AA RR GG BB

A represents the alpha value (transparency), R is rd, G is green, B is blue. Each group defines intensity of each of the colors channels, A is alpha, R is red, G is green, B is blue. Full intensity on the alpha channel means no alpha (FF) and no intensity (00) means full alpha. So a transparent pixel color value is 0x00rrggbb.

like image 28
raju-bitter Avatar answered Sep 24 '22 12:09

raju-bitter