Flash中的AS3 copyPixels从BitmapData转换为jpeg截图

时间:2012-06-14 08:36:05

标签: actionscript-3 flash screenshot

我有代码在swf中创建舞台的实时屏幕截图。 之后,它保存为jpeg。一切都好。

只是,我不需要整个舞台,我只需要剪裁:

x,y:357,341 widt,身高:319,483

我的代码看起来像这样..

我在何处以及如何插入copypixels功能?

(我是Flash新手,所以对我很轻松: - )

function mouseReleaseSave(event:MouseEvent):void {
import com.adobe.images.JPGEncoder;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequestHeader;
import flash.net.URLRequest;

var jpgSource:BitmapData = new BitmapData(this.stage.stageWidth, this.stage.stageHeight);
jpgSource.draw(this.stage);
var jpgEncoder:JPGEncoder = new JPGEncoder(70);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);

//set the request's header,method and data
var header:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream");
var loader:URLLoader = new URLLoader();
//sends jpg bytes to saveJPG.php script
var myRequest:URLRequest = new URLRequest("saveJPG.php");
myRequest.requestHeaders.push(header);
myRequest.method = URLRequestMethod.POST;
myRequest.data = jpgStream;
loader.load(myRequest);
//fire complete event;
loader.addEventListener(Event.COMPLETE,saved);
function saved(e:Event){
    //trace the image file name
    trace(loader.data);
}

}

1 个答案:

答案 0 :(得分:1)

这应该有所帮助:

var subArea:Rectangle = new Rectangle(0,0, 319,483 );
var newBmp:Bitmap = new BitmapData( 319,483 );
var cutoutBmp:Bitmap = new Bitmap( newBmp, PixelSnapping.ALWAYS, true );
cutoutBmp.bitmapData.draw( jpgSource, new Matrix(1, 0, 0, 1, -357, -341) , null, null, subArea, true );