flex:创建UI元素的屏幕截图

时间:2010-02-22 20:49:14

标签: actionscript-3

我想制作自定义as3 ui元素(从Canvas扩展)的屏幕截图,然后将图像上传到服务器上。

你能帮我一个小例子吗?


我正在尝试执行以下操作:

// This is UI component extended from Canvas
var chessBoard:ChessBoard = new ChessBoard();
    // I displayed pieces on the board, but didn't add it to the stage (I just need a 
    // a screenshot, not need them on the canvas)
    chessBoard.displayPosition(DataStorage.getInstance().getStoredPosition(0));
var img:ImageSnapshot = ImageSnapshot.captureImage(chessBoard, 300, new PNGEncoder());   
var obj:Object = new Object();
    obj.complexity = complexity.value;
    obj.img = img;
httpService.send(obj);

并收到此错误:

  

ArgumentError:错误#2015:无效   的BitmapData。在   flash.display :: BitmapData()at   mx.graphics::ImageSnapshot$/captureBitmapData()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\graphics\ImageSnapshot.as:186]    在   mx.graphics::ImageSnapshot$/captureImage()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\graphics\ImageSnapshot.as:282]    在   UI :: SendForm /发送()[/用户/奥列格/文档/ chess_problems / problemme / SRC / UI / SendForm.mxml:53]    在

     

> UI :: SendForm / ___ SendForm_Button1_click()[/用户/奥列格/文档/ chess_problems / problemme / SRC / UI / SendForm.mxml:16]

此错误是由于缺少画布的宽度和高度造成的。我设置它们,这有助于以这种方式创建位图数据:

var bitmapData:BitmapData = new BitmapData(chessBoard.width,chessBoard.height);
var encoder:PNGEncoder = new PNGEncoder();
var data:ByteArray = encoder.encode(bitmapData); 

我想知道如何通过httpService将图像发送到服务器?有办法吗?还是data = image file?

2 个答案:

答案 0 :(得分:1)

以下是关于在AS3中做过这件事的人的帖子:

答案 1 :(得分:0)

这是可能的,虽然我从未这样做过,但这可能对您有用:http://www.flash-db.com/Tutorials/snapshot/