The following code inverts the colors of an image and returns the inverted image as an Image object. As parameter it needs the container of the image (a canvas).
private function invertImageColor(canvas:Canvas):Image { var newImage:Image = new Image(); newImage.source = Image( canvas.getChildAt(canvas.numChildren-1)).source; newImage.blendMode = BlendMode.INVERT; return newImage; }
Afterwards you can add it to what ever container you want.
Another approach is the following: “adding the new inverted image to the same container of the original image”.
private function invertImageColorAdded(canvas:Canvas):Image { if (canvas.numChildren > 1) { canvas.removeChildAt(1); return canvas.getChildAt(0); } else { var newImage:Image = canvas.addChild(new Image()) as Image; newImage.source = Image(canvas.getChildAt(0)).source; newImage.blendMode = BlendMode.INVERT; return canvas.getChildAt(1) } }
This also receives the canvas as parameter then checks to see if an inversion is already present and removing it if so.
This is it.
Tags: ActionScript, image, inverted
This post was written by Andrei Ionescu
Views: 1208


















