Screenshot of stage

蹲街弑〆低调 提交于 2019-12-08 09:36:48

问题


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.



来源:https://stackoverflow.com/questions/946748/screenshot-of-stage

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