Objective:

Need to create a snapshot from flex, what would you do.

Solution:

Make any canvas or vbox or hbox as a base64encodeded string using flex commands, and pass it server script. on server script decode the base64 string that you have received.

Image.mxml



import mx.graphics.ImageSnapshot;
import mx.core.UIComponent;
public function getBase64String(component:UIComponent):void {
var urlRequest:URLRequest = new URLRequest("http://bearly.in/image.php");
urlRequest.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
vars.image = ImageSnapshot.encodeImageAsBase64(ImageSnapshot.captureImage(component));
urlRequest.data = vars;
navigateToURL( urlRequest, "_self" );
}
public function getBase64String1(component:UIComponent):String {
var snapshot:ImageSnapshot = ImageSnapshot.captureImage(component);
var b64String:String = ImageSnapshot.encodeImageAsBase64(snapshot);
return b64String;
}
public function getBase64String2(component:UIComponent):String {
return ImageSnapshot.encodeImageAsBase64(ImageSnapshot.captureImage(component));
}

encode on client side(flex app) and decode on server side(php,java or .net)

image.php



So easy is int it.

Print Friendly
This entry was posted on Monday, April 11th, 2011 at 2:38 am and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.