Screenshot of stage

2019-06-09 03:52发布

问题:

Is it possible to take a screenshot (dump image) of the Stage and save it to my web server?

回答1:

This should do the trick:

var myBitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
myBitmapData.draw(stage);

(actually i'm not sure if you can do a draw() on the stage directly, you might need to do this on whatever is on top of your DisplayList instead)

Then use something like this code: http://henryjones.us/articles/using-the-as3-jpeg-encoder

var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(myBitmapData);

var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");

To send it to the server.