Flex/actionscript snapshot with clipping rectangle and scaling matrix

ε祈祈猫儿з 提交于 2019-12-10 11:35:13

问题


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 capturebitmapdata too, but with that I can't even get a proper image. See here. So I don't want to use that.


回答1:


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.



来源:https://stackoverflow.com/questions/2160353/flex-actionscript-snapshot-with-clipping-rectangle-and-scaling-matrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!