Take a screenshot in Flex and send it to ASP.NET
In Adobe Flex 3, you can get a bitmap image of any control by using this code (you’ll need to import "mx.graphics.ImageSnapshot"):
var snapshot:ImageSnapshot = ImageSnapshot.captureImage(backgroundCanvas);
By default, it uses PNG encoding.
If you want to then send this image to the server, use this code:
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);
Reading the uploaded file is easy using 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;
}
}

