# Ditmapdata draw and masked image

**URL:** https://forum.kirupa.com/t/ditmapdata-draw-and-masked-image/308700
**Category:** Uncategorized
**Created:** [April 28, 2010, 1:21pm UTC](https://forum.kirupa.com/t/ditmapdata-draw-and-masked-image/308700 "2010-04-28T13:21:01Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![werehunt](https://avatars.discourse-cdn.com/v4/letter/w/b782af/32.png) [@werehunt](https://forum.kirupa.com/u/werehunt)
#### Post date: [April 28, 2010, 1:21pm UTC](https://forum.kirupa.com/t/ditmapdata-draw-and-masked-image/308700/1 "2010-04-28T13:21:01Z")

</div>

I am trying to copy an image.  
The green stuff on the first image is a mask (which is not set, its just there to show it)  
Everything works fine when I dont set a mask to an image (picture 1)  
But when I set the mask I get picture 2.

What I want is to copy a part of the image which is visible when the mask is set. I know what size the mask and image are going to be so I can calculate the size of the area which i need to copy.

[![](http://img69.imageshack.us/img69/653/96400640.jpg)](http://img69.imageshack.us/i/96400640.jpg/)

[![](http://img203.imageshack.us/img203/5205/70000518.jpg)](http://img203.imageshack.us/i/70000518.jpg/)

This is the code I am using, image has registration point in the center, thats why i use matrix.translate (not sure if its the right way).  
Also there is no image scaling applied (there might be later), thats why I am using matrix.scale.

```auto
var _reflectionHolder:Sprite = new Sprite();
addChild(_reflectionHolder);
_reflectionHolder.y =_targetObject.y + _targetObject.height / 2 + 10;

var _bitmapData:BitmapData = new BitmapData(_targetObject.width, _targetObject.height, true, 0x00000000);
var _matrix:Matrix = new Matrix();
_matrix.scale(_targetObject.scaleX, _targetObject.scaleY);
_matrix.translate(_targetObject.width/2,_targetObject.height/2);
_bitmapData.draw(_targetObject, _matrix);

var _reflectionBitmap:Bitmap = new Bitmap(_bitmapData);
_reflectionHolder.addChild(_reflectionBitmap);

```
