我正在制作一个拖放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");
}
答案 0 :(得分:1)
我只会改写Evan的回答。
在BitmapData上使用adobe.corelib的JPEGEncode或PNGEncode后,使用FileReference保存文件。请记住,旧版本的FlashPlayer(&lt; 10)不会在驱动器上保存文件!