<?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>Stroep &#187; AIR</title> <atom:link href="http://blog.stroep.nl/tag/air/feed/" rel="self" type="application/rss+xml" /><link>http://blog.stroep.nl</link> <description>Just a collection of random works - Mark Knol</description> <lastBuildDate>Tue, 10 Jan 2012 20:09:53 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Saving images with AIR - Create a wallpaper using AS3 only</title><link>http://blog.stroep.nl/2008/09/saving-images-with-air-create-a-wallpaper-using-as3-only/</link> <comments>http://blog.stroep.nl/2008/09/saving-images-with-air-create-a-wallpaper-using-as3-only/#comments</comments> <pubDate>Sat, 13 Sep 2008 13:20:34 +0000</pubDate> <dc:creator>Mark Knol</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[Generative art]]></category> <category><![CDATA[AIR]]></category> <category><![CDATA[experiment]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[wallpaper]]></category><guid isPermaLink="false">http://blog.stroep.nl/?p=99</guid> <description><![CDATA[I'm experimenting with AIR, because I heard saving a ByteArray ( for example encoded PNG or JPG ) should be quite simple. You don't need PHP or another serverside script for this, just write directly on you disk. Well, just check it out.I created an example of how to get it work. The image will be save in the same directory as your AIR application.<img src="/wp-content/uploads/small-wallpaper.jpg" alt="Cool wallpaper created with AS3" width="430" /> Click the read-more button to find out how to create a cool AS3 wallpaper.]]></description> <content:encoded><![CDATA[<p>Looking for class to save images? <a href="/2008/08/as3-imagesaver-class-v10/">Check out ImageSaver.as</a></p><p>I&#8217;m experimenting with AIR, because I heard saving a ByteArray ( for example encoded PNG or JPG ) should be quite simple. You don&#8217;t need PHP or another serverside script for this, just write directly on you disk. Well, just check it out.</p><p>See this example of how to get it work. The image will be save on the same directory as your AIR application.<div class="bbCSH" style="font-family: monospace;"><span style="color: #808080; font-style: italic;">// use adobe&#8217;s encoder to create a byteArray</span><br /> <span style="color: #000000; ">var</span> jpgEncoder:JPGEncoder = <span style="color: #000000; ">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&#41;</span>;<br /> <span style="color: #000000; ">var</span> byteArray:ByteArray = jpgEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span> bitmapData <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// set an filename</span><br /> <span style="color: #000000; ">var</span> filename:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;cool-image.jpg&quot;</span>;</p><p><span style="color: #808080; font-style: italic;">// get current path</span><br /> <span style="color: #000000; ">var</span> file:File = File.<span style="color: #006600;">applicationDirectory</span>.<span style="color: #006600;">resolvePath</span><span style="color: #66cc66;">&#40;</span> filename <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// get the native path </span><br /> <span style="color: #000000; ">var</span> wr:File = <span style="color: #000000; ">new</span> File<span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">nativePath</span> <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// create filestream </span><br /> <span style="color: #000000; ">var</span> stream:FileStream = <span style="color: #000000; ">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// &nbsp;open/create the file, set the filemode to write in order to save.</span><br /> stream.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span> wr , FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// write your byteArray into the file. </span><br /> stream.<span style="color: #006600;">writeBytes</span> <span style="color: #66cc66;">&#40;</span> byteArray, <span style="color: #cc66cc;">0</span>, byteArray.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// close the file. </span><br /> stream.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p><p><span style="color: #808080; font-style: italic;">// That&#8217;s it.</span><br /> &nbsp;</div><p><strong>Is that it? This would be a boring post if I stopped right now <img src='http://blog.stroep.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong><br /> I experimented to <em>create a colorful cool wallpaper using AS3 only</em> and save it using AIR. If you don&#8217;t got AIR or just don&#8217;t want to use it, I recommend using my ImageSave class.</p><p><a href="http://www.flickr.com/photos/markknol/2852527273/" target="_blank"><img src="/wp-content/uploads/cool-wallpaper.jpg" alt="Cool wallpaper created with AS3" width="430" /></a><script type="text/javascript">google_ad_client = "pub-8026631169002810";
/* 468x15, gemaakt 30-6-08 */
google_ad_slot = "6262097246";
google_ad_width = 430;
google_ad_height = 15;</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead show_ads.js"></script><br/><br/></p><p><strong>This is my code to create this wallpaper:</strong><br /> Feel free to play with the code, but post a link to your experiment / wallpaper here.</p><div class="bbCSH" style="font-family: monospace;"><span style="color: #0066CC;">package</span> <br /> <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">images</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filesystem</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">filters</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <span style="color: #0066CC;">import</span> nl.<span style="color: #006600;">stroep</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">*</span>;<br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Sprite</span><br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">public</span> <span style="color: #000000; ">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> bitmapData:BitmapData = <span style="color: #000000; ">new</span> BitmapData <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1280</span>, <span style="color: #cc66cc;">1024</span>, <span style="color: #000000; ">false</span>, 0&#215;000000 <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create colorful radial lines</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> shape:Shape = <span style="color: #000000; ">new</span> Shape<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; ">var</span> i:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>; i &lt; <span style="color: #cc66cc;">1900</span>; i++<span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create some weird colors using sinus</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">30</span>, <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> i * <span style="color: #cc66cc;">9</span> <span style="color: #66cc66;">&#41;</span> * i / <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span> * 0xffffff, <span style="color: #cc66cc;">0.4</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// do some weird sin/cos moves</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> i/<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">&#41;</span>*i/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, &nbsp;<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span> i/<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">&#41;</span>*i/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// add it multiple times using other blendmodes, isn&#8217;t that what we do all the time in PhotoShop?</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">NORMAL</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #0066CC;">ADD</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">MULTIPLY</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> shape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">OVERLAY</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// cool! filters! Add some blur to our lines to make a nice blurry background</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span> bitmapData, bitmapData.<span style="color: #006600;">rect</span>, <span style="color: #000000; ">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> , <span style="color: #000000; ">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create colorful radial lines</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> anotherShape:Shape = <span style="color: #000000; ">new</span> Shape<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anotherShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; ">var</span> j:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>; j &lt; <span style="color: #cc66cc;">1900</span>; j++<span style="color: #66cc66;">&#41;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create some weird lines with weird sizes</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> lineWidth:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">50</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>j / <span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> &gt;&gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> <span style="color: #0066CC;">color</span>:<span style="color: #0066CC;">Number</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> j <span style="color: #66cc66;">&#41;</span> * j / <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span> * 0xFFFFFF<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anotherShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span> lineWidth, <span style="color: #0066CC;">color</span>, <span style="color: #cc66cc;">0.2</span>, <span style="color: #000000; ">false</span>, LineScaleMode.<span style="color: #006600;">NORMAL</span>, CapsStyle.<span style="color: #006600;">SQUARE</span>, JointStyle.<span style="color: #006600;">MITER</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anotherShape.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">sin</span><span style="color: #66cc66;">&#40;</span> j/<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">&#41;</span>*j/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>, &nbsp;<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">cos</span><span style="color: #66cc66;">&#40;</span> j/<span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">&#41;</span>*j/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// cool! filters! Add some blur to our lines to make a little blurry</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">applyFilter</span><span style="color: #66cc66;">&#40;</span> bitmapData, bitmapData.<span style="color: #006600;">rect</span>, <span style="color: #000000; ">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> , <span style="color: #000000; ">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// blendmode ADD is awesome</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> anotherShape, <span style="color: #000000; ">null</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #006600;">OVERLAY</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create some text</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> <span style="color: #0066CC;">textfield</span>:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; ">new</span> <span style="color: #0066CC;">TextField</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #006600;">antiAliasType</span> = AntiAliasType.<span style="color: #006600;">NORMAL</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">htmlText</span> = <span style="color: #ff0000;">&quot;&lt;font face=&#8217;Arial&#8217; color=&#8217;#FFFFFF&#8217; size=&#8217;60&#8242;&gt;FUN WITH BITMAPDATA&lt;/font&gt; &lt;br/&gt; &lt;font face=&#8217;verdana&#8217; color=&#8217;#FFFFFF&#8217; size=&#8217;20&#8242;&gt;&lt;B&gt;CREATE YOUR OWN WALLPAPER WITH FLASH&lt;/b&gt;&lt;/font&gt;&quot;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">autoSize</span> = TextFieldAutoSize.<span style="color: #0066CC;">LEFT</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// cool! filters! Add blur to your text</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #006600;">filters</span> = <span style="color: #66cc66;">&#91;</span> <span style="color: #000000; ">new</span> BlurFilter<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">20</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// draw textfield into bitmapdata, and use a matrix to set its position to center screen</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">textfield</span>, <span style="color: #000000; ">new</span> Matrix<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textWidth</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> ,<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textHeight</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; ">null</span>, BlendMode.<span style="color: #0066CC;">ADD</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// reset the filters, just add DropShadow</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">textfield</span>.<span style="color: #006600;">filters</span> = <span style="color: #66cc66;">&#91;</span> <span style="color: #000000; ">new</span> DropShadowFilter<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">45</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0.3</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#93;</span> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// draw textfield again</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">textfield</span>, <span style="color: #000000; ">new</span> Matrix<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textWidth</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> ,<span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> &#8211; <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">textfield</span>.<span style="color: #0066CC;">textHeight</span>/<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// show the bitmapData, just add it to the stage, using the Bitmap Class</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; ">new</span> Bitmap <span style="color: #66cc66;">&#40;</span> bitmapData <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// use adobe&#8217;s encoder to create a byteArray</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> jpgEncoder:JPGEncoder = <span style="color: #000000; ">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> byteArray:ByteArray = jpgEncoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span> bitmapData <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// set an filename</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> filename:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;cool-wallpaper.jpg&quot;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// get current path</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> file:File = File.<span style="color: #006600;">applicationDirectory</span>.<span style="color: #006600;">resolvePath</span><span style="color: #66cc66;">&#40;</span> filename <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// get the native path </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> wr:File = <span style="color: #000000; ">new</span> File<span style="color: #66cc66;">&#40;</span> file.<span style="color: #006600;">nativePath</span> <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create filestream </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; ">var</span> stream:FileStream = <span style="color: #000000; ">new</span> FileStream<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// &nbsp;open/create the file, set the filemode to write; because we are going to save</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span> wr , FileMode.<span style="color: #006600;">WRITE</span><span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// write your byteArray into the file. </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.<span style="color: #006600;">writeBytes</span> <span style="color: #66cc66;">&#40;</span> byteArray, <span style="color: #cc66cc;">0</span>, byteArray.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&#41;</span>;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// close the file. That&#8217;s it.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.<span style="color: #0066CC;">close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp;&nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br /> <span style="color: #66cc66;">&#125;</span></div><p><a href="http://blog.stroep.nl/?flattrss_redirect&amp;id=99&amp;md5=4159aa2abe4f863d94cd05087775031c" title="Flattr" target="_blank"><img src="http://blog.stroep.nl/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded> <wfw:commentRss>http://blog.stroep.nl/2008/09/saving-images-with-air-create-a-wallpaper-using-as3-only/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> </channel> </rss>
