# Bitmapdata with rotation, scaling and translation

**URL:** https://forum.kirupa.com/t/bitmapdata-with-rotation-scaling-and-translation/186832
**Category:** flash
**Created:** [April 24, 2006, 9:51pm UTC](https://forum.kirupa.com/t/bitmapdata-with-rotation-scaling-and-translation/186832 "2006-04-24T21:51:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![leraptor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/leraptor/32/2353_2.png) [@leraptor](https://forum.kirupa.com/u/leraptor)
#### Post date: [April 24, 2006, 9:51pm UTC](https://forum.kirupa.com/t/bitmapdata-with-rotation-scaling-and-translation/186832/1 "2006-04-24T21:51:47Z")

</div>

I am in an urgent need of help!

I’ve spent hours and hours on this problem, but I don’t even have a clue on how to dot it…

I’m doing a digital camera simulation : the user is presented with a big background, he have to take a partial snapshot of that background. As with any camera, he can Zoom in/Zoom out and rotate.

I use a Bitmapdata class to save the snapshot he takes, it works (with a bit of hack) when I don’t move the background. But when I Zoom/Rotate the background, \*\*the snapshot is still taken from the original background! \*\* As if I didn’t do any modification.

I’m thinking about [COLOR=“Navy”]using a rotation and scale matrix [/COLOR] then apply it to the bitmap data, but I don’t know what values to put in those matrix. I’m helpless in math.

Please help!

Here’s the code

```auto

function capture(nr) {
	var myMatrix:Matrix = new Matrix();
	snapshot = new BitmapData(follow._width, follow._height);
	myMatrix.rotate(-1*photo1_mc._rotation); // Tried this for the rotation but it didn't work
	var translateMatrix:Matrix = new Matrix();
	translateMatrix.translate(-1*(follow._x-580), -1*(follow._y-423)); // translation matrix to translate the whole photo.b
	myMatrix.concat(translateMatrix);
	snapshot.draw(photo1_mc, myMatrix);
	capture_mc.attachBitmap(snapshot, 1);
	
}

```

and here’s the FLA :  
[Bitmap FLA](http://www.trouvertravail.com/bitmap.zip)

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [April 24, 2006, 11:28pm UTC](https://forum.kirupa.com/t/bitmapdata-with-rotation-scaling-and-translation/186832/2 "2006-04-24T23:28:03Z")

</div>

The _BitmapData.draw_ method doesn’t apply transformations (rotation, scaling, translation) made to the movie clip when rendering, as you have found out. And as you have also found out, you have to use a matrix to apply these transformations. In the case of movie clips, modifying these transform these properties directly changes the values of each movie clips transform.matrix property. So all you need to do is pass this matrix to the _draw_ method and you’re good to go:

```auto
snapshot.draw(photo1_mc, photo1_mc.transform.matrix);

```

In your case you’ll also have to translate the matrix:

```auto
function capture(nr) {
 snapshot = new BitmapData(follow._width, follow._height);
 var m:Matrix = photo1_mc.transform.matrix;
 m.tx = -follow._x + 580;
 m.ty = -follow._y + 423;
 snapshot.draw(photo1_mc, m);
 capture_mc.attachBitmap(snapshot, 1);
}

```

---

<div class="post-metadata">

### Author: ![leraptor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/leraptor/32/2353_2.png) [@leraptor](https://forum.kirupa.com/u/leraptor)
#### Post date: [April 24, 2006, 11:48pm UTC](https://forum.kirupa.com/t/bitmapdata-with-rotation-scaling-and-translation/186832/3 "2006-04-24T23:48:28Z")

</div>

YES YES YES YES !!!  
I really don’t know how to thank you! This is working PERFECTLY:beer:

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [April 25, 2006, 12:10am UTC](https://forum.kirupa.com/t/bitmapdata-with-rotation-scaling-and-translation/186832/4 "2006-04-25T00:10:13Z")

</div>

Just glad to help :p:
