开发者

Flex/actionscript snapshot with clipping rectangle and scaling matrix

var snapshot:ImageSnapshot = ImageSnapshot.captureImage(someSprite);
var file:FileReference = new FileReference();
file.save(snapshot.data,'abc.png');

In the above code I am able to capture an image.

But I also want to apply a scalingMatrix(for zoomIn/Out) and a clipping rectangle to it.

How to do it?

I tried capt开发者_高级运维urebitmapdata too, but with that I can't even get a proper image. See here. So I don't want to use that.


sw = someSprite.stage.stageWidth;            
sh = someSprite.stage.stageHeight;           
var cr:Rectangle = new Rectangle(x,y,cw,ch);//you have to check that this clip rectangle should not overshoot your stage
//cr is the clip rectangle
var bmp:BitmapData = new BitmapData(sw,sh);
bmp.draw(someSprite,null,null,null,cr);

var bmp1:BitmapData = new BitmapData(cw,ch);
bmp1.copyPixels(bmp,cr,new Point(0,0));
var enc:JPEGEncoder = new JPEGEncoder();
var data:ByteArray = encoder.encode(bmd1);
new FileReference().save(data,'image.jpeg');

The above code allows you to draw only the portion inside the clip rectangle. In my case I didn't have to take into account a scaling matrix, even though I was using zoom In/Out features.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜