的Flex /动作快照剪贴矩形和调整矩阵矩形、快照、矩阵、动作

2023-09-08 11:36:11 作者:小混混

  VAR快照:将ImageSnapshot = ImageSnapshot.captureImage(someSprite);
var文件:的FileReference =新的FileReference();
file.save(snapshot.data,'abc.png');
 

在上面的code,我能够捕捉到的图像。

但我也想申请一个scalingMatrix(用于zoomIn输入/输出)和剪辑矩形吧。

怎么办呢?

我试过 capturebitmapdata 过,但我甚至不能得到正确的图像。请参见这里。所以我不希望使用它。

解决方案

  SW = someSprite.stage.stageWidth;
SH = someSprite.stage.stageHeight;
VAR CR:矩形=新的Rectangle(X,Y,CW,CH); //你要检查这个剪辑矩形不宜过冲你的舞台
// CR是剪裁矩形
VAR BMP:的BitmapData =新的BitmapData(SW,SH);
bmp.draw(someSprite,NULL,NULL,NULL,CR);

VAR BMP1:的BitmapData =新的BitmapData(CW,CH);
bmp1.copyPixels(BMP,CR,新点(0,0));
VAR ENC:JPEGEn codeR =新JPEGEn codeR();
VAR数据:的ByteArray = EN coder.en code(BMD 1);
新的FileReference()保存(数据,image.jpeg');
 

以上code,您可以只绘制剪辑矩形内的部分。 在我来说,我没有考虑到缩放矩阵,即使 我是用放大/缩小功能。

var snapshot:ImageSnapshot = ImageSnapshot.captureImage(someSprite);
var file:FileReference = new FileReference();
file.save(snapshot.data,'abc.png');
速看 5个前沿的科技产品,总有一个是你需要的

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.

解决方案

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.