Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : rotate a BitmapData object


abeall
2/11/2006 10:00:25 PM
I understand that the Matrix can be used to apply a rotated transformation with
the BitmapData.draw() method, but how do you rotate an already drawn bitmap? I
can't seem to figure it out from the F1 docs... the BitmapData class has no
method to do any transformations, so I go over to the Matix class and can only
find how that can be applied to a MovieClip with the Transform object, or
BitmapData.draw(), not an already drawn BitmapData...

bmp = original_bmp.clone();
this.attachBitmap(bmp,1,false,true);
//bmp.rotatePixels??

Thanks
kglad
2/12/2006 12:00:00 AM
kglad
2/12/2006 12:00:00 AM
import flash.display.BitmapData;
import flash.geom.*;
import flash.filters.*;
bmp1 = new BitmapData(1, 1, false, 0x00aaaaaa);
bmp1.draw(ovalMC);
b = new BlurFilter(25, 25, 2);
r = bmp1.generateFilterRect(bmp1.rectangle, b);
mc1.onPress = function() {
trace(r.width);
bmp = new BitmapData(r.width, r.height, false, 0x00aaaaaa);
_root.createEmptyMovieClip("mc3", _root.getNextHighestDepth());
mc3.attachBitmap(bmp, _root.getNextHighestDepth());
mat1 = new Matrix();
mat1.rotate(Math.PI/4);
mat2 = new Matrix();
mat2.translate(r.width/2, r.height/2);
mat1.concat(mat2);
bmp.draw(ovalMC, mat1);
bmp.applyFilter(bmp, bmp.rectangle, new Point(0, 0), b);
};
kglad
2/12/2006 2:08:15 AM
you can always draw bmp to another bitmap object. or you can manipulate the
container movieclip:

bmp = original_bmp.clone();
this.attachBitmap(bmp,1,false,true);
this._rotation=whatever;

or because you probably don't want to rotate everything on that timeline:

bmp = original_bmp.clone();
this.createEmptyMovieClip("holderMC",this.getNextHighestDepth());
this.holderMC.attachBitmap(bmp,1,false,true);
this.holderMC._rotation=whatever;
this.attachBitmap(bmp,1,false,true);
abeall
2/12/2006 2:20:13 AM
Thanks, I appreciate it kglad. The only problem - and deal killer for that
method - is I need to rotate the bitmap pixels, not the timeline, because I'm
trying to apply a filter and have the filter angled. Rotating a MC and apply a
filter, the filter ignores the rotation. Basically, I'm trying to do this:

bitmap clone of a movieclip
rotate bitmap pixels X
apply heavy y axis blur
rotate bitmap/container MC -X

So is there no way to transform a bitmap after the draw() has been called?

resulting in motion blur
abeall
2/13/2006 1:07:53 AM
Exactly... so the only way to resize a bitmap rectangle is to draw a new one?
Seems a bit... odd, and round-about... oh well...

Thanks a bunch kglad, let's continue this discussion in my other thread since
they are basically the same now.

Thanks again
AddThis Social Bookmark Button