I've added a black and white filter onto an image using the following code:
var n:Number = 1/3;
var matrix:Array = [n,n,n,0,0,
n,n,n,0,0,
n,n,n,0,0,
0,0,0,1,0];
var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix);
_bitmap.bitmapData.applyFilter(_buffer, _sourceRect, new Point(), cmf);
I now want to be able to remove this filter but I can't seem to figure out how. I've read that if I clear the _bitmap.filters array it should be removed, but when I check, this array is empty.
Does anyone have any suggestion about how I might do this?
Edit I'm using the FlashPunk game engine and I'm manipulating the bitmapData from the Image.as class. All my code is written and compiled using FlashDevelop.
EDIT
I was not able to apply a filter directly onto the bitmap due to the fact that the image class in the flashpunk flashpunk engine was drawing the bitmap using the bitmapData.CopyPixels() function. The filter was not applied to the bitmapData and was therefore not being drawn.
I've changed the render method to use the bitmapData.draw() function which uses the actual bitmap to draw the image.
I can now add a filter to my bitmap by doing the following:
_bitmap.filters = [ColorMatrixFilter];
I can then remove my filters by doing the following:
_bitmap.filter = [];