在Flex应用中,我们经常需要制作一些截图效果,下面给大家分享截图制作step by step:
Flex端UI呈现:
应用API:import mx.graphics.ImageSnapshot;
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(source);
var encoded_jpg:JPEGEncoder = new JPEGEncoder(100);
var imageByteArray:ByteArray = imageSnap.data as ByteArray;
Flex向Server发送请求:
- var req:URLRequest = new URLRequest();
- req.method = URLRequestMethod.POST;
- req.data = snapshot.data;
- req.contentType="application/octet-stream";
- req.url = "snapshotuploadhandler.aspx";
- var loader:URLLoader = new URLLoader;
- loader.load(req);
Base64算法: ByteArray -> String
在URLRequest之中,data可传递Binary格式的数据。
但在下列代码之中,URLVariables做为Object,其内容均为key-value格式,所以,Img对象赋值传参过程以String类型呈现:
var variables:URLVariables = new URLVariables();
variables.img = encoded;
variables.vid = '77';
request.data = variables;
为处理这一情况,我们需要提供img对象的Base64解码。
Base64编码与解码例程参见: http://www.cordyblog.cn/?action=show&id=49
clear,搞定,大家可以试一下,加油!