Posts Tagged ‘BitmapData’

BitmapData and transparency

August 4th, 2011

If you used draw method from BitmapData class to copy some DisplayObject with transparency you may notice that all transparent pixels turned white. This is because you didn’t set properly parameters in BitmapData construcotr.

BitmapData(width:int, height:int, transparent:Boolean=true, fillColor:uint=0xffffffff)

By default BitmapData fills it’s background with white and to avoid this you have to set fillColor parameter to any transparent color.

var bitmapData:BitmapData = new BitmapData(someWidth, someHeight, true, 0x00ffffff);
bitmapData.draw(someDisplayObject);

ByteArray to BitmapData. Loading image in SWF format.

August 4th, 2011

If you load an image saved in SWF format and you would like to have it as BitmapData then the following three functions will solve the problem. » Read more: ByteArray to BitmapData. Loading image in SWF format.

ByteArray to BitmapData. Loading image with FileReference.

August 3rd, 2011

If you load a graphic file with the FileReference class you will get it as a ByteArray and you will probably like to convert it to BitmapData. » Read more: ByteArray to BitmapData. Loading image with FileReference.

How to get RGB color values from BitmapData?

July 30th, 2011

BitmapData object has two methods: getPixel() and getPixel32 which return hexadecimal color value without and with alpha channel respectively. You can easily extract RGB values from hexadecimal notation using the code below:

var pixel:uint = bitmapData.getPixel32(x, y);
var alpha:uint = pixel >> 24 & 0xff;
var red:uint = pixel >> 16 & 0xff;
var green:uint = pixel >> 8 & 0xff;
var blue:uint = pixel & 0xff;

How to disable mouse events on transparent parts of PNG image?

July 30th, 2011

Transparent area in vector graphics doesn’t generate any mouse events simply because it holds no data. In case of raster graphics every transparent area is a solid block of pixels with aplha channel equal zero. All transparent pixels in a PNG file behave like non-tranparent ones what sometimes can be treated as unwanted feature. » Read more: How to disable mouse events on transparent parts of PNG image?

BitmapData and Perlin noise

November 21st, 2010

Just a little application to play with BitampData’s perlinNoise function.
» Read more: BitmapData and Perlin noise

Taking components’ snapshots with ImageSnapshot class

August 7th, 2010

The ImageSnapshot is a static class that provides methods to take snapshots of flex components and optionally convert them into a base64 encoded string.
» Read more: Taking components’ snapshots with ImageSnapshot class

Adjusting color values with ColorTransform class

August 5th, 2010

The ColorTransform class allows you to adjust the color values of any display object. The color adjustment or color transformation can be applied to all four channels: red, green, blue, and alpha transparency.
» Read more: Adjusting color values with ColorTransform class

Flexmaniaks on Facebook