# Bitmap Eraser

**URL:** https://forum.kirupa.com/t/bitmap-eraser/249174
**Category:** flash
**Created:** [January 16, 2008, 4:03am UTC](https://forum.kirupa.com/t/bitmap-eraser/249174 "2008-01-16T04:03:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Groady](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/groady/32/3750_2.png) [@Groady](https://forum.kirupa.com/u/Groady)
#### Post date: [January 16, 2008, 4:03am UTC](https://forum.kirupa.com/t/bitmap-eraser/249174/1 "2008-01-16T04:03:33Z")

</div>

[LEFT]I’m trying to make an AS3 version of senocular’s Erase and Redraw [http://www.senocular.com/flash/source.php?id=0.175](http://www.senocular.com/flash/source.php?id=0.175). I’ve gone over the code and converted it over to AS3. It all seems pretty straight forward. My problem is when I draw with the eraser it erase’s with the entire bitmap shape not just the alpha. I can not figure out why.

The below code creates the actual eraser bitmapData. A white square with a transparent circle.

```auto

var eraser:BitmapData = drawEraser();

        private function drawEraser():BitmapData {
            
            var diamX:int = 50;
            var diamY:int = 50;
            
            // Below creates a black circle that will be the eraser's shape.
            eraserShape.graphics.clear();
            eraserShape.graphics.beginFill(0x000000, 1);
            eraserShape.graphics.drawEllipse(0,0,diamX,diamY);
            eraserShape.graphics.endFill();
            
            // New bitmapData created and filled with white.
            var eraserShapeBMD:BitmapData = new BitmapData(diamX, diamY, true, 0);
            eraserShapeBMD.fillRect(eraserShapeBMD.rect, 0xFFFFFFFF);
            
            // Copy the black brush shape to the bitmapData object. Image will then be a black circle on a solid white background.
            eraserShapeBMD.draw(eraserShape);
            // Copy the red channel to the alpha channel. This leaves a solid white square with a transparent circle.
            eraserShapeBMD.copyChannel(eraserShapeBMD, eraserShapeBMD.rect, zeroPoint, BitmapDataChannel.RED, BitmapDataChannel.ALPHA);
    
            drawEraserCursor();
            return eraserShapeBMD;
        }

```

The below function is triggered when the mouse is pressed and moves.

```auto

private function drawPoint (xMouse:int, yMouse:int):void {            

    var zeroPoint:Point = new Point(0,0);
    selectedLayer.bitmapData.copyPixels(selectedLayer.bitmapData, eraser.rect, new Point(xMouse-eraser.width/2, yMouse-eraser.height/2), eraser, zeroPoint, false);
        
}

```

Any help would be great.  
[/LEFT]
