Return to Snippet

Revision: 47236
at June 3, 2011 08:17 by Winkyboy


Initial Code
private function invert(oldBmp:Bitmap):Bitmap {
	var source:BitmapData = oldBmp.bitmapData;
	var destin:BitmapData = source;
	var rectan:Rectangle = new Rectangle(0, 0, source.width, source.height);
	
	// Replace all transparent pixels with a solid color
	destin.threshold(source, rectan, new Point(), "==", 0x00000000,0xFFFF0000);
	// Replace all the pixels greater than 0xf1f1f1 by transparent pixels
	destin.threshold(source, rectan, new Point(), "==", 0xff656565,0x0000FF00);
	
	return new Bitmap(destin);
}

Initial URL


Initial Description
This inverts the transparency on a Bitmap (probably supplied a PNG source) that specifically has two colors in it; "#656565" and "transparent" - you can tweak the threshold lines specifically if you'd like to modify that to use a range, or whatever.

Adapted from http://stackoverflow.com/questions/608087/flex-actionscript-white-to-transparent and http://www.sephiroth.it/tutorials/flashPHP/thresold/

Initial Title
AS3 invert image transparency

Initial Tags


Initial Language
ActionScript 3