Bitmapdata with rotation, scaling and translation

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


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

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:

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

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

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);
}

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

Just glad to help :p: