<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FlexOut &#187; bitmapData</title>
	<atom:link href="http://flex.exposedout.net/tag/bitmapdata/feed/" rel="self" type="application/rss+xml" />
	<link>http://flex.exposedout.net</link>
	<description>i am an itemrendrer in the making!</description>
	<lastBuildDate>Fri, 13 May 2011 10:05:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Export to Jpeg in flex.</title>
		<link>http://flex.exposedout.net/2011/05/13/export-to-jpeg-in-flex-using-screen-capture/</link>
		<comments>http://flex.exposedout.net/2011/05/13/export-to-jpeg-in-flex-using-screen-capture/#comments</comments>
		<pubDate>Fri, 13 May 2011 05:05:47 +0000</pubDate>
		<dc:creator>Vikram singh</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[innovation]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[bitmapData]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[JPEGencoder]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[save file]]></category>
		<category><![CDATA[save jpeg]]></category>

		<guid isPermaLink="false">http://flex.exposedout.net/?p=343</guid>
		<description><![CDATA[There is always a need to way to export some sort of a report out to the user, previously I used the classical use of a serverside script in Java or PHP to enable user to take a screenshot of the component or the entire application. Since the flash player 10 provides the feature to [...]


Related posts:<ol><li><a href='http://flex.exposedout.net/2011/05/05/save-file-as-pdf-in-flex/' rel='bookmark' title='Permanent Link: Save file as PDF in flex'>Save file as PDF in flex</a></li>
<li><a href='http://flex.exposedout.net/2009/05/25/caching-images-in-flex/' rel='bookmark' title='Permanent Link: Caching images in Flex'>Caching images in Flex</a></li>
<li><a href='http://flex.exposedout.net/2008/09/09/uploads-file-via-httphttps/' rel='bookmark' title='Permanent Link: uploads file via http/https'>uploads file via http/https</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There is always a need to way to export some sort of a report out to the user, previously I used  the classical use of a serverside script in Java or PHP  to enable user to take a screenshot of the component or the entire application. Since the flash player 10 provides the feature to save local file using file reference I am going to exploit that feature and export some BITMAP content into a Jpeg file.</p>
<p>following is the code for taking a snapshot of the component on some event/action</p>
<p>Prerequisite for making this components work.</p>
<ul>
<li>Build project in <a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4">flex 4.0 + SDK</a></li>
<li>Use flash player 10 and above (MUST)</li>
<li>Include <a href="https://github.com/mikechambers/as3corelib">Corelib.swc</a> for JPEGEncoder to work</li>
</ul>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">//file reference declaration to enable user to save file to local system.</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> file:FileReference = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">//function can be called on button click or context menu click or any other interaction</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> captureIt<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> df : DateFormatter = <span style="color: #000000; font-weight: bold;">new</span> DateFormatter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
df.<span style="color: #006600;">formatString</span> = <span style="color: #ff0000;">&quot;DD-MM-YY HH:NN&quot;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;<br />
bitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>,<span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> bitmap : Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bitmapData<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> jpg:JPEGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPEGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray = jpg.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bitmapData<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> dt : <span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> dtStr : <span style="color: #0066CC;">String</span> = df.<span style="color: #006600;">format</span><span style="color: #66cc66;">&#40;</span>dt.<span style="color: #0066CC;">time</span><span style="color: #66cc66;">&#41;</span>;<br />
file.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>ba,<span style="color: #ff0000;">'Screenshot at'</span>+dt.<span style="color: #0066CC;">time</span>+<span style="color: #ff0000;">'.jpg'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Explanation</strong></p>
<p><strong>BitmapData ()</strong><br />
The BitmapData () function takes a height and width of the component which has to be converted to image, i have used <em>this </em> you can very well use any UIComponent or DisplayObject.</p>
<p><strong>bitmapData.draw(this,new Matrix ());</strong><br />
This is the place where the actual conversion takes place (where the bitmap data is drawn), Again you can use any UIComponent or DisplayObject in <em>this </em>place.</p>
<p><strong>Bitmap Encoding: jpg.encode (bitmapData);</strong><br />
The component or screen area to be captured  is converted into BITMAP data so that it could be encoded into Jpeg file format for saving it, you can also use a PNG or GIF encoder in this place as per your requirement. At this place the Bitmap data is encoded into a JPEG file format.</p>
<p><strong>var ba : ByteArray = jpg.encode (bitmapData);</strong><br />
Since BITMAP data cannot be saved directly to the local system we first convert it into a ByteArray.</p>
<p><strong>Date : dt.time</strong><br />
The date  is only used to give each screenshot a unique timestamps so that each time the function is called a new file is saved.</p>
<p><strong>file.save ( ba,&#8217;Screenshot at&#8217;+dt.time+&#8217;.jpg&#8217; );</strong><br />
Now we pass the byte array  to the file reference and also pass the name  by which the file has to be saved, as shown in the function above.</p>
<p>Vollia you can now save JPEG file to your local  file system via Flex without using any third party Serverside script to do so. No more HTTP request and error handling to take care of.</p>
<p><strong>GO MAKE THE WORLD A BETTER PLACE<br />
Say no to paper, No need to print  graphs when you can save them to jpeg </strong></p>


<p>Related posts:<ol><li><a href='http://flex.exposedout.net/2011/05/05/save-file-as-pdf-in-flex/' rel='bookmark' title='Permanent Link: Save file as PDF in flex'>Save file as PDF in flex</a></li>
<li><a href='http://flex.exposedout.net/2009/05/25/caching-images-in-flex/' rel='bookmark' title='Permanent Link: Caching images in Flex'>Caching images in Flex</a></li>
<li><a href='http://flex.exposedout.net/2008/09/09/uploads-file-via-httphttps/' rel='bookmark' title='Permanent Link: uploads file via http/https'>uploads file via http/https</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://flex.exposedout.net/2011/05/13/export-to-jpeg-in-flex-using-screen-capture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caching images in Flex</title>
		<link>http://flex.exposedout.net/2009/05/25/caching-images-in-flex/</link>
		<comments>http://flex.exposedout.net/2009/05/25/caching-images-in-flex/#comments</comments>
		<pubDate>Mon, 25 May 2009 09:27:54 +0000</pubDate>
		<dc:creator>Vikram singh</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[bitmapData]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[hashmap]]></category>
		<category><![CDATA[image]]></category>

		<guid isPermaLink="false">http://guavus.wordpress.com/?p=226</guid>
		<description><![CDATA[Caching of  image data  in your Flex application is one of the best ways to avoid loading those large images again and again, and this  can  improve performance and reduce overhead of loading external resources. We are not discussing about using the cacheAsBitmap property to improve rendering performance or the cachePolicy property to speed up [...]


Related posts:<ol><li><a href='http://flex.exposedout.net/2011/05/13/export-to-jpeg-in-flex-using-screen-capture/' rel='bookmark' title='Permanent Link: Export to Jpeg in flex.'>Export to Jpeg in flex.</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Caching of  image data  in your Flex application is one of the best ways to avoid loading those large images again and again, and this  can  improve performance and reduce overhead of loading external resources.</p>
<p>We are not discussing about using the <span style="color:#008000;">cacheAsBitmap </span>property to improve rendering performance or the <span style="color:#008000;">cachePolicy </span>property to speed up animations. Its the caching of actual bitmap data of an image. As the 2 are different in one case we just cache the image data of an image that has to be animated and component doesnot reload any image. in the other case we  reload the data on demand  for example user profile with display picture. In this case the picture mostly does not change (well it does but  we can handle it differently) so we dont need to reload the image at each time the user profile data of the same person is called.. so we can impliment a cache here.</p>
<p>You’ll need a hash map to store the image data. A Dictionary or an associative array will also work just fine. Loading an image for the first time is the same as usual. You create a new Image object and add a listener for the COMPLETE event or it could be any of your custom event for the sake of example we will follow :</p>
<blockquote><p>var image : Image = new Image ();<br />
image.addEventListener (Event.COMPLETE, onImageLoad);</p></blockquote>
<p>Once the image has finished loading, you add a copy of the bitmap data to the hash map using the image URL as the hash key as the URL for any image will always be distinct:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageCache : hashMap = <span style="color: #000000; font-weight: bold;">new</span> hashMap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">// create hashmap only once</span><br />
<br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onImageLoad <span style="color: #66cc66;">&#40;</span>event : Event<span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> image : Image = event.<span style="color: #0066CC;">target</span> as Image;<br />
<span style="color: #000000; font-weight: bold;">var</span> imageURL : <span style="color: #0066CC;">String</span>  = image.<span style="color: #006600;">source</span>;<br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span> imageCache.<span style="color: #006600;">containsKey</span> <span style="color: #66cc66;">&#40;</span>imageURL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> bitmapData : BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<br />
<span style="color: #66cc66;">&#40;</span>image.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">width</span>, image.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">height</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;<br />
bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span>image.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>;<br />
imageCache.<span style="color: #006600;">put</span> <span style="color: #66cc66;">&#40;</span>imageURL, bitmapData<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>The above method is called and the image is cached in the hash map. Now you can use the image as many times as we want without ever having to load it again. A good exapmle of this could be  loading user profile whenever you reload the profile data one need not fetch the  user profile picture. the picture can directly be accessed from the hashmap.</p>
<p>How do we use the image we stored, Its simple you need to check the hash map each time you call for the loading the image just check if you’ve already cached it:</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">// check the hashmap when ever next you want to load the image</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>imageCache.<span style="color: #006600;">containsKey</span> <span style="color: #66cc66;">&#40;</span>imageURL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><br />
image.<span style="color: #006600;">source</span> = <span style="color: #000000; font-weight: bold;">new</span> Bitmap <span style="color: #66cc66;">&#40;</span>imageCache.<span style="color: #006600;">getValue</span> <span style="color: #66cc66;">&#40;</span>imageURL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>thats it now you can use the cache whenever required.</p>


<p>Related posts:<ol><li><a href='http://flex.exposedout.net/2011/05/13/export-to-jpeg-in-flex-using-screen-capture/' rel='bookmark' title='Permanent Link: Export to Jpeg in flex.'>Export to Jpeg in flex.</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://flex.exposedout.net/2009/05/25/caching-images-in-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

