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.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" styleName="plain">
<mx:Script>
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));
}
</mx:Script>
<mx:Canvas id="draw">
<mx:Label text="Hello" fontSize="170"/>
</mx:Canvas>
<mx:Button label="Submit" click="getBase64String(draw)" x="10" y="168"/>
</mx:Application>
encode on client side(flex app) and decode on server side(php,java or .net)
<?php
header('Content-Type: image/png');
header("Content-Disposition: attachment; filename=image.png");
echo base64_decode($_POST["image"]);
?>
So easy is int it.
Recent comments
6 days 3 hours ago
1 week 23 hours ago
9 weeks 2 days ago
23 weeks 5 days ago
38 weeks 1 day ago