By Minidxer | April 26, 2008
在Adobe Flex 3中,你可以通过下面的代码获取任何控件并保存为bitmap图片(需要import “mx.graphics.ImageSnapshot”,想必大名鼎鼎的snapshot大家都应该知道吧?)。
- var snapshot:ImageSnapshot = ImageSnapshot.captureImage(backgroundCanvas);
默认的话,使用的是PNG格式的编码。如果你想将图片传递到服务器端,那就用下面的代码:
- 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);
在ASP.NET中读取上传了的文件是非常轻松的,代码如下:
- private byte[] readPostedFile()
- {
- if (Request.ContentLength > 0)
- {
- byte[] buffer = new byte[Request.ContentLength];
- using (BinaryReader br = new BinaryReader(Request.InputStream))
- br.Read(buffer, 0, buffer.Length);
- return buffer;
- }
- else
- {
- return null;
- }
- }