# BitmapData is frustrating me

**URL:** https://forum.kirupa.com/t/bitmapdata-is-frustrating-me/314121
**Category:** flash
**Created:** [September 18, 2010, 8:56pm UTC](https://forum.kirupa.com/t/bitmapdata-is-frustrating-me/314121 "2010-09-18T20:56:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sFoster83](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@sFoster83](https://forum.kirupa.com/u/sFoster83)
#### Post date: [September 18, 2010, 8:56pm UTC](https://forum.kirupa.com/t/bitmapdata-is-frustrating-me/314121/1 "2010-09-18T20:56:50Z")

</div>

Okay first off I am getting bitmapData from display objects like so

```php

private function getDrawData(forObj : DisplayObject) : BitmapData {
    var bmpData : BitmapData = new BitmapData(forObj.width, forObj.height, true, 0);
    bmpData.draw( forObj );
    return bmpData;
}

```

I have this PaintedImage class, consisting of a PaintedImage, and a PaintedMask.

In this case  
PaintedImage = A picture of a face  
PaintedMask = BitmapData with a filled blue circle

Basically I want to apply paintedMask as a mask for PaintedImage, but nothing seems to be working. I have had both display objects using cacheAsBitmap=true.

I tried using two images, loading the data and setting one as a mask of the other but just failure. Using the default mask stuff gave me absolutely no effect. Anyone know why, or can provide me any help?

So then I tried doing this manually… i had a few ideas, such as

```php

private function getManualMask(forImage : BitmapData, forMask : BitmapData) : BitmapData {
    var result : BitmapData = forImage;
    var rect : Rectangle = new Rectangle(0, 0, forImage.width, forImage.height);
   
    result.threshold( forMask, rect, new Point(0, 0), '==', drawColor, 0x00000000); 
    
    return result;
}

```

Above, the idea was that anything that matches the blue fill color should be set as a transparent pixel in the forImage. But that didn’t work…

I also tried this  
result.copyChannel( forMask, rect, new Point(0, 0), BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA);  
but that didn’t copy over the alpha transparencies for the pixels either… i guess i don’t understand how copyChannel or threshold work.

So applying a mask programatically seems to have failed me too.  
Can anyone help me out here because I have no idea how to use bitmapData’s functions and apparently masks are too complicated for me

The only way I could get a mask to work was by using a sprite and having all of the data applied to it through the Graphics object. But that doesn’t work for me because some of the stuff i need to apply as a mask comes from bitmap data calculations and not just graphics drawing commands.
