Realtime Thumbnails of Flex UIComponents
Here's an experiment that I have been toying with lately... I took the concepts from an older blog posting on Bitmap objects and applied it to an actual usable interface. It's not the prettiest application in the world, but its still pretty darn cool (in my opinion)... hence it is an "experiment". This example shows how to generate thumbnails of instantiated UIComponent objects in real time. So, every time that the UIComponent is updated, so is its thumbnail.
The thumbnail generation for this example uses the same function from my previous post:
The first panel (red background) contains a mx:TextBox control. As you type in the textbox, you can see the top left thumbnail being updated. No, you can't read it when it is that small, but you can see the changes happening. :)
The second panel (green background) contains a mx:DateChooser component. As you select dates, or mouseover dates, you can see the changes reflected in the thumbnail image.
The third panel (blue background) starts getting a lot more interesting. This example uses code based off of actionscript.com's drawing example to have a basic paintbrush application. As you draw on the canvas, you can see the thumbnail getting updated with your changes.
The fourth panel (purple background) uses an actionscript "FireFly" effect, based on an AS3 example that Keun Lee modified and showed to me. I limited the # of pixels being set, and the maximum size to increase performance in this example. You can see that the thumbnail gets updated with the firefly image.
Click on the "play" button below to view a FLV video of a demonstration of this in action:
Click on the "play" button above to view a FLV video of a demonstration of this in action:
If you are having any performance issues with this example, it is related to the 4th panel (FireFlys)... This is very processor intensive. Download the code, comment that out, and you should see a huge improvement. Feel free to contact me with any questions/comments at andrew.trice[ at ]cynergysystems.com
Now, you might be wondering where this would actually have any practical application... The first thing that comes to my mind is a charting dashboard. You could have thumbnails of various charts, changing in real-time, based on real data. If you want to drill into a chart, you select it, and view the full-sized version of the chart. The second thing that comes to mind is image editing... Lets say you were creating a RIA-based version of a photo/image editor. You could give thumbnail previews of multiple open images, or you could use the thumbnails to show mini-versions of layers of the composition. There have to be a ton of useful applications for this, which are just waiting to be discovered.
Note: This code technique will currently only work with instantiated components. Components that are null/uninitialized will throw exceptions, which I haven't looked into yet.
The thumbnail generation for this example uses the same function from my previous post:
private function getUIComponentBitmapData( target : UIComponent ) : BitmapDataBasically, I created 4 different panel objects and 4 different states. In each state, one of the panels is "maximized" to fill the content area. On the top of the application, I have a mx:TileList control that will hold my thumbnails. On creationComplete of the application, I create an ArrayCollection for the dataProvider of the mx:TileList. In that ArrayCollection, I put refferences to the instantiated components. In the itemRender for the mx:TileList, I use the references to the instantiated components to generate thumbnails of the components using the getUIComponentBitmapData function. I use a timer in the main application to dispatch an "updateImage" event ever 500 milliseconds, which notifies the itemRenderer to update the thumbnails.
{
var bd : BitmapData = new BitmapData( target.width, target.height );
var m : Matrix = new Matrix();
bd.draw( target, m );
return bd;
}
The first panel (red background) contains a mx:TextBox control. As you type in the textbox, you can see the top left thumbnail being updated. No, you can't read it when it is that small, but you can see the changes happening. :)
The second panel (green background) contains a mx:DateChooser component. As you select dates, or mouseover dates, you can see the changes reflected in the thumbnail image.
The third panel (blue background) starts getting a lot more interesting. This example uses code based off of actionscript.com's drawing example to have a basic paintbrush application. As you draw on the canvas, you can see the thumbnail getting updated with your changes.
The fourth panel (purple background) uses an actionscript "FireFly" effect, based on an AS3 example that Keun Lee modified and showed to me. I limited the # of pixels being set, and the maximum size to increase performance in this example. You can see that the thumbnail gets updated with the firefly image.
Click on the "play" button below to view a FLV video of a demonstration of this in action:
Click on the "play" button above to view a FLV video of a demonstration of this in action:
If you are having any performance issues with this example, it is related to the 4th panel (FireFlys)... This is very processor intensive. Download the code, comment that out, and you should see a huge improvement. Feel free to contact me with any questions/comments at andrew.trice[ at ]cynergysystems.com
Now, you might be wondering where this would actually have any practical application... The first thing that comes to my mind is a charting dashboard. You could have thumbnails of various charts, changing in real-time, based on real data. If you want to drill into a chart, you select it, and view the full-sized version of the chart. The second thing that comes to mind is image editing... Lets say you were creating a RIA-based version of a photo/image editor. You could give thumbnail previews of multiple open images, or you could use the thumbnails to show mini-versions of layers of the composition. There have to be a ton of useful applications for this, which are just waiting to be discovered.
Note: This code technique will currently only work with instantiated components. Components that are null/uninitialized will throw exceptions, which I haven't looked into yet.





5 Comments:
Thank you for this great piece of code.
For w3eb design purposes I like to do wireframe drawing of key components of the web page but like to be able to sketch out the whole site / app design and drill down into individual screens and show the flow across screens. So eg I would show search components on one page, and then draw lines to the results pages and onto to detail pages etc. So, if I could draw the outline, and then explde up each item for details work, coupled with your thumbnails that's a very powerful tool, for me anyway.
As you say also, a very powerful paradigm for dashboards and also for eg stockcharting - eg might have a few thumbnails of stocks being tracked and then explode up the one that hits an alert . Lots of possibilities for the ideas you have prototyped here.
Hi Andrew,
I've used this code to get the image from a UIComponent a lot, but now I'm getting into having to print them...
When you use the code that you have for getting the bitmap data from the uicomponent you get a white background that fills the rest of the space...
say you want the image from a VBox that has only an image in it... say the image is only 1/4 of the size of the VBox... then you end up getting a white background that fills the rest of the space... is there anyway to fix that?
Axel
Axel, if you are using Flex 3, you might want to look at the ImageSnapshot class. It has everything you need for generating higher dpi screen captures.
higher dpi, and it supports transparency... i don't remember the exact syntax, but be sure to use 0x00000000 as the background color. this value is transparent, where 0x000000 is black. the extra byte represents the alpha channel
Post a Comment
<< Home