Question

Is there a way to apply a colorTransform to a BitmapData in a circle rather than in a rectangle?

Instead of erasing rectangular parts of an image by reducing the alpha channel as in the code below, I'd like to do it in circles.

 _bitmap.colorTransform(new Rectangle(mouseX-d/2, mouseY-d/2, d, d),
 new ColorTransform(1, 1, 1, .5, 0, 0, 0, 1));

I do have some code which loops through the pixels, extracts the alpha value and uses setPixel but it seams significantly slower than the colorTransform function.

Was it helpful?

Solution

Try creating a circle using the drawing API (flash.display.Graphics) and then drawing that onto the bitmap data with BlendMode.ERASE. That might solve your problem, if I understand it correctly.

var circle : Shape = new Shape;
circle.graphics.beginFill(0xffcc00, 1);
circle.graphics.drawEllipse(-50, -50, 100, 100);

// Create a transformation matrix for the draw() operation, with
// a translation matching the mouse position.
var mtx : Matrix = new Matrix();
mtx.translate(mouseX, mouseY);

// Draw circle at mouse position with the ERASE blend mode, to
// set affected pixels to alpha=0.
myBitmap.draw(circle, mtx, null, BlendMode.ERASE);

I'm not 100% sure that the ERASE blend mode works satisfyingly with the draw() command, but I can't see why it shouldn't. Please let me know how it works out!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top