is there a way for flash AS3 to take a snapshot of a frame then save it as jpeg

主宰稳场 提交于 2019-12-03 22:38:31

问题


is there a way for flash AS3 to take a snapshot of the frame and then save it as jpeg with out using classes


回答1:


Sure... try searching on google... there are tons of ways. That is assuming you are ok with the standard flash classes. If you literally mean no classes at all then good luck to you.

Here is one way of doing it. flash-php-upload

Basically the key points are you create a JPEG Encoder that will encode your image a JPEG (you could do a PNG if you want also) like this:

var jpgEncoder:JPGEncoder;
jpgEncoder = new JPGEncoder(90);

Next you encode the stage by first drawing its data to a bitmap, then ecoding that:

var bitmapData:BitmapData = new BitmapData(stage.width, stage.height);
bitmapData.draw(stage, new Matrix());

img = jpgEncoder.encode(bitmapData);

Now depending on what flash you are using you can do the following to prompt the user to save:

var file:FileReference = new FileReference();
file.save(img, "filename.jpg");

Or if you want to save it to the server you can do the following:

var sendHeader:URLRequestHeader = new URLRequestHeader("Content-type","application/octet-stream");
var sendReq:URLRequest = new URLRequest("path-to-php.php");

sendReq.requestHeaders.push(sendHeader);
sendReq.method = URLRequestMethod.POST;
sendReq.data = img;

var sendLoader:URLLoader;
sendLoader = new URLLoader();
sendLoader.addEventListener(Event.COMPLETE, imageSentHandler);
sendLoader.load(sendReq);

And then you need a PHP file with the following:

<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
$filename = "filename.jpg";
$fp = fopen( $filename,"wb");
fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );
fclose( $fp );
echo "filename=".$filename."&base=".$_SERVER["HTTP_HOST"].dirname($_SERVER["PHP_SELF"]);
}
?>

Please be aware that I have not tested this code for errors but the general idea is correct and you should be able to use it and make the changes you need for your program.



来源:https://stackoverflow.com/questions/9404723/is-there-a-way-for-flash-as3-to-take-a-snapshot-of-a-frame-then-save-it-as-jpeg

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