Hi,
I am trying to create the eraser functionlity can you please help me.
My issue -
I drawing with the pencile over the image and want to erase that graphic but not able to suucees please give some solution.
My backgroud page is image and i am adding zoomIn/ZoomOut functionality to image.
Is there solution to erase only graphic part and Image will remain as it is?
I want to create the Eraser like on the following site :- http://pixlr.com/editor/
Thanks
Hi Sam,
as kglad suggested, you can manipulate bitmapData of the pencil drawing (assuming the pencil is drawing to bitmapData - fastest / best drawing).
I created an example where in the background, there's a Bitmap image (just noise for the sake of the experiment but you can load real picture) and on top of that there's a Bitmap filled with semi-transparent red color. As you move your mouse, you erase the red bitmap.
You can check the example here: http://dev.flashlabs.eu/examples/eraser/
The code:
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
public class Eraser extends Sprite {
private var bitmap:Bitmap;
public function Eraser() {
var background:Bitmap = createBackground();
addChild(background);
bitmap = createBitmap();
addChild(bitmap);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
protected function mouseMoveHandler(event:MouseEvent):void {
var bd:BitmapData = bitmap.bitmapData;
var x:Number = bitmap.mouseX;
var y:Number = bitmap.mouseY;
var brushSize:Number = 20;
bd.fillRect(new Rectangle(x - brushSize / 2, y - brushSize / 2, brushSize, brushSize), 0x00000000);
}
public function createBackground():Bitmap {
var bd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
bd.perlinNoise(5, 5, 5, 5, true, true);
return new Bitmap(bd);
}
public function createBitmap():Bitmap {
var bd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xeeFF0000);
return new Bitmap(bd);
}
}
}
North America
Europe, Middle East and Africa
Asia Pacific