Doing 'screenshots' in Flex and sending them to ColdFusion
Flex will create a JPG of the panel and send it off to CF.
Here is a look at some of the code, you can also view the source from the Flex application.
First, I import the JPGEncoder class. I store a lot of AS libraries and components in one location and add them to the 'source path' of my application.
Next, I create a method that converts a UI component into BitmapData.
{
var bitmapData:BitmapData = new BitmapData(target.width, target.height);
var matrix:Matrix = new Matrix();
bitmapData.draw(target, matrix);
return bitmapData;
}
As you can see, this method can take any UI element as an argument. This method returns the bitmap data of the UI element that was passed in.
Next, I create a method that handles calling the above method, and then sends the result to ColdFusion:
var bitmapData:BitmapData = getBitmapData(target);
var jpgEncoder:JPGEncoder = new JPGEncoder(90);
var imgData:ByteArray = jpgEncoder.encode(bitmapData);
imageService.saveImage(imgData);
}
This method also takes any UI element and uses it when calling getBitmapData(). It also creates an instance of the JPGEncoder class. The '90' that is passed into the constructor of JPGEncoder is the 'quality' of the resulting JPG.
Next we need to create a
The CFC itself is very simple, it contains 1 method whose only argument is the binary data that is our image.
You will see that inside the method all we do is a
Lastly, we need some code that will fire off this entire event inside our Flex application.
10:35 AM
|
Labels:
Flex Samples
|
This entry was posted on 10:35 AM
and is filed under
Flex Samples
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
0 comments:
Post a Comment