带有剪切矩形和缩放矩阵的 Flex/actionscript 快照 [英] Flex/actionscript snapshot with clipping rectangle and scaling matrix

查看:23
本文介绍了带有剪切矩形和缩放矩阵的 Flex/actionscript 快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

但我也想对它应用一个 scalingMatrix(用于放大/缩小)和一个裁剪矩形.

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

怎么做?

我也尝试了 capturebitmapdata,但是我什至无法获得正确的图像.请参阅此处.所以我不想用那个.

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.

这篇关于带有剪切矩形和缩放矩阵的 Flex/actionscript 快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆