我正在开发一个拖放式 Flash 游戏,在您放置所有可移动的部分后,我想要一个按钮,可以让人们保存整个舞台的屏幕截图。
我搜索了不同的示例,但无法使此代码正常工作。
这是AS3
snap_btn.addEventListener(MouseEvent.CLICK, snapShot );
function snapShot( evt:MouseEvent ):void
{
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData (stage.width, stage.height);
jpgSource.draw(stage);
var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);
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");
}
PHP的
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
// get bytearray
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $jpg;
}
?>
我最终得到了这个工作,我摆脱了 php
snap_btn.addEventListener(MouseEvent.CLICK, snapShot );
function snapShot( evt:MouseEvent ):void
{
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData(stage.width, stage.height);
jpgSource.draw(stage);
var jpgEncoder:JPGEncoder = new JPGEncoder(80);
var imgByteData:ByteArray = jpgEncoder.encode(jpgSource);
file = new FileReference();
file.save(imgByteData, "Haven_Big_Dream_Map.jpg");
}