Why is BitmapData transparency not transparent?

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

From everything I read, this should be transparent. I see a big black square. What can cause this?

+7
source share
4 answers

This doesn't make sense: I tried the following code:

 package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; public class TestBitMap extends Sprite { public function TestBitMap() { var imageYellow:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0xFFFFFF00)); var imageTransparent:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0)); var imageSemiTransparent:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0x99000000)); imageTransparent.x = 25; imageTransparent.y = 25; imageSemiTransparent.x = 50; imageSemiTransparent.y = 50; addChild(imageYellow); addChild(imageTransparent); addChild(imageSemiTransparent); } } } 

And I got a yellow box with a translucent black box above it. "ImageTransparent" was completely invisible.

I also tried your method with creating BitMap, and then modified bitmapData. No difference, still invisible.

San.chez: 0 is 0x00000000, no matter what. This is an unsigned integer; ActionScript does not magically change it. Your link is good, though.

+2
source

use this

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

instead

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

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

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

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

// EDIT:

Dennis Kraeger and the line are right, 0x00000000 == 0. It seems that the problem is in a different place, and not in the code that you inserted.

+14
source

ActionScript uses 32-bit hexadecimal numbers to represent color values ​​with transparency. ARGB colors, since 32-bit variables are set in four groups of 8 bits each / or 2 hexadecimal:

In binary format: AAAAAAAA RRRRRRRR GGGGGGGG BBBBBBBB

Hexadecimal: AA RR GG BB

A represents the alpha value (transparency), R is rd, G is green, B is blue. Each group determines the intensity of each of the color channels, A - alpha, R - red, G - green, B - blue. The full alpha channel intensity means no alpha (FF), and the (00) intensity means full alpha. Thus, the color value of the transparent pixel is 0x00rrggbb.

+3
source

You can create or transfer BitmapData to the constructor of the new Bitmap, or edit it by reference after creating it. Both options work:

 package { //Imports import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; //Document Class public class Main extends Sprite { //Constructor public function Main() { var bmpData:BitmapData = new BitmapData(200, 200, true, 0x5500FF00); var bmp:Bitmap = new Bitmap(bmpData); addChild(bmp); var bmp2:Bitmap = new Bitmap(); bmp2.bitmapData = new BitmapData(200, 200, true, 0x55FF0000); bmp2.x = bmp2.y = 200; addChild(bmp2); } } } 
+3
source

All Articles