<?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>Jozef Chúťka&#039;s blog &#187; Bitmap</title>
	<atom:link href="http://blog.yoz.sk/tag/bitmap/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yoz.sk</link>
	<description>My life, my work</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:40: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>Pixel Bender Displacement Map Fakes 3D Effect (update)</title>
		<link>http://blog.yoz.sk/2010/05/pixel-bender-displacement-map-fakes-3d-effect/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pixel-bender-displacement-map-fakes-3d-effect</link>
		<comments>http://blog.yoz.sk/2010/05/pixel-bender-displacement-map-fakes-3d-effect/#comments</comments>
		<pubDate>Mon, 10 May 2010 12:39:19 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[displacement]]></category>
		<category><![CDATA[pixel bender]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1601</guid>
		<description><![CDATA[Few days before I saw an amazing 3d effects on VidazPhoto. That made me want to master this effect. So, starting today morning I played around with flex and pixel bender and here are the results. I have created simple pixel bender kernel that uses monochromatic bitmapData to calculate amount of displacement for each pixel. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/pixelbenderdisplace1.jpg" alt="" title="pixelbenderdisplace" width="200" height="100" class="alignleft size-full wp-image-1612" /></p>
<p>Few days before I saw an amazing 3d effects on <a href="http://www.vdiazphoto.com/">VidazPhoto</a>. That made me want to master this effect. So, starting today morning I played around with flex and pixel bender and here are the results. I have created simple pixel bender kernel that uses monochromatic bitmapData to calculate amount of displacement for each pixel. All you have to do, in order to make your 2D images become 3D, is to create monochromatic map (black &amp; white image) with the same dimensions as the original image (use lighter colors for closer objects, darker colors for distant ones). Than, based on rotation, push correct amounts of full displacement (dx, dy displacements for full white color) into shader. The displacement is linear starting on 0, 0 for black color, up to dx, dy for white color. All sources available to download.</p>
<p><span id="more-1601"></span></p>
<p>First, here is the final application with displacement map used to fake 3D effect:</p>
<div style="text-align:center;width:465px;"><iframe title="flash on 2010-5-10 - wonderfl build flash online" scrolling="no" src="http://wonderfl.net/blogparts/6r6S" width="465" height="490" style="border:1px black solid;"></iframe><a href="http://wonderfl.net/c/6r6S" title="flash on 2010-5-10 - wonderfl build flash online">flash on 2010-5-10 &#8211; wonderfl build flash online</a></div>
<p>Click mouse to change images, move mouse to rotate image. <a href="http://blog.yoz.sk/examples/pixelBenderDisplacement/PBDisplacement.as">Full ActionScript 3 code</a> can be also downloaded from wonderfl. The core of this app are those few lines:</p>
<pre class="brush: as3; title: ; notranslate">shader.data.map.input = Bitmap(mapLoader.content).bitmapData;
shader.data.dx.value = [imageContainer.rotationY];
shader.data.dy.value = [-imageContainer.rotationX];

filter = new ShaderFilter(shader);
imageLoader.filters = [filter];</pre>
<p>simple displacement with pixel bender &#8211; <a href="http://classes.yoz.sk/sk/yoz/displacing/SimpleDisplacer.pbk">SimpleDisplacer.pbk</a></p>
<pre class="brush: xml; title: ; notranslate">&lt;languageVersion : 1.0;&gt;

kernel DisplacementMap
&lt;
	namespace : &quot;sk.yoz&quot;;
	vendor : &quot;Yoz&quot;;
	version : 1;
	description : &quot;Displacement by bitmap map&quot;;
&gt;
{
	input image4 src;
	input image1 map;
	output pixel4 dst;

	parameter float dx
	&lt;
		minValue: float(-1000.0);
		maxValue: float(1000.0);
		defaultValue: float(0.0);
		description: &quot;The amount of displacement on x axis.&quot;;
	&gt;;

	parameter float dy
	&lt;
		minValue: float(-1000.0);
		maxValue: float(1000.0);
		defaultValue: float(0.0);
		description: &quot;The amount of displacement on y axis.&quot;;
	&gt;;

	void evaluatePixel()
	{
		float2 pos = outCoord();
		float amount = sampleLinear(map, pos);
		float2 displacedPos = float2(
			pos.x + dx * amount,
			pos.y + dy * amount);
		dst = sampleLinear(src, displacedPos);
	}
}</pre>
<p>I have used image1 input type for monochromatic map (black and white bitmap), its enough and its superfast.</p>
<p>Due to great success, I have added fader parameter. Fader can be used for depth of field or, alpha transparency etc. You can download <a href="http://classes.yoz.sk/sk/yoz/displacing/FadeDisplacer.pbk">advanced pixel bender source here</a>.</p>
<div style="text-align:center;width:465px;"><iframe title="Pixel Bender Displacement Map Fakes 3D Effect + Depth Of Field - wonderfl build flash online" scrolling="no" src="http://wonderfl.net/blogparts/50I3" width="465" height="490" style="border:1px black solid;"></iframe><a href="http://wonderfl.net/c/50I3" title="Pixel Bender Displacement Map Fakes 3D Effect + Depth Of Field - wonderfl build flash online">Pixel Bender Displacement Map Fakes 3D Effect + Depth Of Field &#8211; wonderfl build flash online</a></div>
<p>Did you know you can make <a href="http://blog.yoz.sk/2010/06/anaglyphs-with-pixel-bender-and-depth-map/">anaglyphs using this technique</a>?</p>
<p>See standalone versions &amp; download on <a href="http://3ddm.yoz.sk">3ddm.yoz.sk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/05/pixel-bender-displacement-map-fakes-3d-effect/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Inline Images</title>
		<link>http://blog.yoz.sk/2010/02/inline-images/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inline-images</link>
		<comments>http://blog.yoz.sk/2010/02/inline-images/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 14:59:44 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[PNGEncoder]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1106</guid>
		<description><![CDATA[Have you ever heard about inline images? Inline images use the data URI scheme to embed images directly within web pages. As defined by RFC 2397, data URIs are designed to embed small data items as &#8220;immediate&#8221; data, as if they were referenced externally. This basicaly means, you can insert base64 encoded byte code of [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/inlineImage-200x122.png" alt="" title="inlineImage" width="200" height="122" class="alignleft size-medium wp-image-1111" /></p>
<p>Have you ever heard about <a href="http://www.websiteoptimization.com/speed/tweak/inline-images/">inline images</a>? Inline images use the data URI scheme to embed images directly within web pages. As defined by RFC 2397, data URIs are designed to embed small data items as &#8220;immediate&#8221; data, as if they were referenced externally. This basicaly means, you can insert base64 encoded byte code of any image directly into html file. Using inline images saves HTTP requests over externally referenced objects. Data URIs can potentially <a href="http://www.greywyvern.com/code/php/binary2base64">store any type of data</a>, not just images!</p>
<p><span id="more-1106"></span></p>
<p>This example creates snapshot of flash application (on left side) and dynamicly (using javascript) creates inline image (right side) with base64 encoded bytes in src attribute. (right side is html &lt;img&gt;)</p>
<p><iframe width="100%" height="300" style="border:none;" src="http://blog.yoz.sk/examples/inlineImages/"></iframe></p>
<p>Application source:</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot;
    enterFrame=&quot;enterFrame()&quot; borderStyle=&quot;solid&quot; borderColor=&quot;#000000&quot;
    backgroundColor=&quot;#ffffff&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    import com.adobe.images.PNGEncoder;
    import com.dynamicflash.util.Base64;

    private function enterFrame():void
    {
        if(!container || !container.width)
            return;

        container.graphics.beginFill(Math.random() * 0xffffff, Math.random());
        container.graphics.drawCircle(
            Math.random() * container.width,
            Math.random() * container.height, Math.random() * 30);

    }

    private function makeSnapshot(source:DisplayObject):void
    {
        var script:String = 'var img = document.getElementById(&quot;img&quot;);'
            + 'if(!img)'
            + '{'
                + 'img = document.createElement(&quot;IMG&quot;);'
                + 'img.id=&quot;img&quot;;'
                + 'document.body.appendChild(img);'
            + '}'
            + 'img.src=&quot;' + getSrc(source) +'&quot;;';
        ExternalInterface.call(&quot;function(){&quot; + script + &quot;}&quot;);
    }

    private function getByteArray(source:DisplayObject):ByteArray
    {
        var bitmapData:BitmapData = new BitmapData(source.width, source.height);
        bitmapData.draw(source);
        var bitmap:Bitmap = new Bitmap(bitmapData);
        return PNGEncoder.encode(bitmapData);
    }

    private function getSrc(source:DisplayObject):String
    {
        var byteArray:ByteArray = getByteArray(source);
        return 'data:image/png;base64,'
            + Base64.encodeByteArray(byteArray);
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Container id=&quot;container&quot; width=&quot;100%&quot; height=&quot;100%&quot;/&gt;
&lt;mx:Button label=&quot;Make Snapshot&quot; click=&quot;makeSnapshot(this)&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>Data URLs save HTTP requests. When combined with CSS sprites, data URLs can save numerous HTTP requests. It would be interesting to see if data URLs can be combined with USEMAPS or make a data URL CSS sprite. Data URLs are a convenient way to create self-enclosed web pages that don&#8217;t rely on external objects to render.</p>
<ul>
<li>Save HTTP requests, avoids adding to object overhead</li>
<li>Save concurrent thread &#8211; browsers default to two simultaneous connections per hostname</li>
<li>HTTPS requests are simplified and performance improved</li>
</ul>
<p>Well, for now I have no idea how can flash benefit from data urls <img src='http://blog.yoz.sk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  but if I come to something I let you know.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/02/inline-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SmoothImage Class (update)</title>
		<link>http://blog.yoz.sk/2010/01/smoothimage-class/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=smoothimage-class</link>
		<comments>http://blog.yoz.sk/2010/01/smoothimage-class/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 15:54:28 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ImageResizer]]></category>
		<category><![CDATA[ResizeEvent]]></category>
		<category><![CDATA[ResizeMath]]></category>
		<category><![CDATA[SmoothImage]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=955</guid>
		<description><![CDATA[While Flex uses bilinear resizing method when scaling images (event for Bitmap.smoothing() method), you won&#8217;t be able to get nice results when downscaling more than 2 times. Inspired by ImageResizer class I have also created SmoothImage Class. This object extends mx.Image and uses ImageResizer.bilinearIterative() class in order to generate smoother resized results. In following example [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/smoothImage1-200x101.jpg" alt="" title="smoothImage" width="200" height="101" class="alignleft size-medium wp-image-963" /></p>
<p>While Flex uses bilinear resizing method when scaling images (event for Bitmap.smoothing() method), you won&#8217;t be able to get nice results when downscaling more than 2 times. Inspired by <a href="http://blog.yoz.sk/2010/01/how-to-resize-an-image-with-actionscript/">ImageResizer class</a> I have also created SmoothImage Class. This object extends mx.Image and uses ImageResizer.bilinearIterative() class in order to generate smoother resized results.</p>
<p><span id="more-955"></span></p>
<p style="clear:both;">In following example mx.Image, <a href="http://cookbooks.adobe.com/post_A_better_smooth_Image_control-9409.html">SmoothImage</a> and <a href="http://classes.yoz.sk/sk/yoz/image/SmoothImage.as">sk.yoz.image.SmoothImage</a> used to demonstrate resizing original 1024x679px image.</p>
<p><iframe src="http://blog.yoz.sk/examples/smoothImage/" width="100%" height="300" style="border:none;"></iframe></p>
<p><a href="http://classes.yoz.sk/sk/yoz/image/SmoothImage.as">sk.yoz.image.SmoothImage</a> class:</p>
<pre class="brush: as3; title: ; notranslate">package sk.yoz.image
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.geom.Matrix;
    import flash.geom.Point;

    import mx.controls.Image;

    import sk.yoz.math.ResizeMath;

    public class SmoothImage extends Image
    {
        protected var _resizeFunction:String = &quot;bilinearIterative&quot;;
        protected var _iterationMultiplier:Number = 2;
        protected var resizedBitmap:Bitmap;

        public function SmoothImage()
        {
            super();
        }

        [Bindable(event=&quot;resizeFunctionChanged&quot;)]
        [Inspectable(category=&quot;Other&quot;, defaultValue=&quot;bilinearIterative&quot;,
            enumeration=&quot;bilinear,bilinearIterative&quot;)]
        public function set resizeFunction(value:String):void
        {
            if(value == resizeFunction)
                return;
            _resizeFunction = value;
            resizeBitmap();
        }

        public function get resizeFunction():String
        {
            return _resizeFunction;
        }

        [Bindable(event=&quot;iterationMultiplierChanged&quot;)]
        public function set iterationMultiplier(value:Number):void
        {
            if(value == iterationMultiplier)
                return;

            _iterationMultiplier = value;
            resizeBitmap();
        }

        public function get iterationMultiplier():Number
        {
            return _iterationMultiplier;
        }

        override protected function updateDisplayList(unscaledWidth:Number,
            unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            resizeBitmap();
        }

        protected function resizeBitmap(... rest):void
        {
            if(!width || !height || !content)
                return;

            if(resizedBitmap &amp;&amp; resizedBitmap.parent)
                resizedBitmap.parent.removeChild(resizedBitmap);

            resizedBitmap = new Bitmap(resizedBitmapData);
            addChild(resizedBitmap);
            content.visible = false;
        }

        protected function get resizeMethod():String
        {
            return maintainAspectRatio ? ResizeMath.METHOD_LETTERBOX
                : ResizeMath.METHOD_RAW;
        }

        protected function get resizedBitmapData():BitmapData
        {
            var bitmapData:BitmapData;

            if(content is Bitmap)
            {
                bitmapData = Bitmap(content).bitmapData
            }
            else
            {
                bitmapData = new BitmapData(content.width / content.scaleX,
                    content.height / content.scaleY, true, 0);
                bitmapData.draw(content);
            }

            var dimensions:Point = ResizeMath.newDimensions(
                new Point(bitmapData.width, bitmapData.height),
                new Point(width, height), resizeMethod, true);

            return ImageResizer[resizeFunction](bitmapData, dimensions.x,
                dimensions.y, resizeMethod, true, iterationMultiplier);
        }
    }
}</pre>
<p>Update (Jan 27, 2010): in sk.yoz.image.SmoothImage</p>
<p>Update (Jun 14, 2010): in sk.yoz.image.SmoothImage</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/01/smoothimage-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>9 slice scale for bitmaps in flash (no hacks)</title>
		<link>http://blog.yoz.sk/2009/11/9-slice-scale-for-bitmaps-in-flash-no-hacks/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=9-slice-scale-for-bitmaps-in-flash-no-hacks</link>
		<comments>http://blog.yoz.sk/2009/11/9-slice-scale-for-bitmaps-in-flash-no-hacks/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 10:37:22 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[9 slice scale]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=645</guid>
		<description><![CDATA[9 slice scale is a nice feature, but when you try to use 9 slice in flash ide on MovieClip with bitmap, you will notice a problem. It will just not work as expected. So first thing you try is &#8220;Break Apart&#8221;, with same result. You are almost there, but due to the solution is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/9slice_result_flash.png"><img src="http://blog.yoz.sk/wp-content/uploads/9slice_result_flash-200x168.png" alt="9slice_result_flash" title="9slice_result_flash" width="200" height="168" class="alignleft size-medium wp-image-649" /></a></p>
<p><a href="http://www.adobe.com/devnet/flex/quickstart/embedding_assets/#EmbeddingImagesScale9">9 slice scale</a> is a nice feature, but when you try to use 9 slice in flash ide on MovieClip with bitmap, you will notice a problem. It will just not work as expected. So first thing you try is &#8220;Break Apart&#8221;, with same result. You are almost there, but due to the solution is not documented you need a small hint: After break apart (ctrl + b), select each of nine slices one by one and group (ctrl + g) individually and voilà its done. See snapshot and result images&#8230;</p>
<div style="clear:both"></div>
<p><span id="more-645"></span></p>
<p>1. original image.png</p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/9slice_image.png"><img src="http://blog.yoz.sk/wp-content/uploads/9slice_image.png" alt="9slice_image" title="9slice_image" width="30" height="30" class="alignnone size-full wp-image-646" /></a></p>
<p>2. <strong>symbol</strong> after break apart</p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/9slice_flash_bitmap_break.png"><img src="http://blog.yoz.sk/wp-content/uploads/9slice_flash_bitmap_break.png" alt="9slice_flash_bitmap_break" title="9slice_flash_bitmap_break" width="207" height="180" class="alignnone size-full wp-image-647" /></a></p>
<p>3. <strong>symbol2</strong> after break apart and individual grouping</p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/9slice_flash_bitmap.png"><img src="http://blog.yoz.sk/wp-content/uploads/9slice_flash_bitmap.png" alt="9slice_flash_bitmap" title="9slice_flash_bitmap" width="210" height="181" class="alignnone size-full wp-image-648" /></a></p>
<p>4. result in flash cs4 ide <strong>symbol</strong>, <strong>symbol2</strong></p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/9slice_result_flash.png"><img src="http://blog.yoz.sk/wp-content/uploads/9slice_result_flash.png" alt="9slice_result_flash" title="9slice_result_flash" width="326" height="274" class="alignnone size-full wp-image-649" /></a></p>
<p>5. 9 slice scale in flex (maintainAspectRatio used just for purpose, no impact on 9 slice scale)</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;horizontal&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    [Embed(source=&quot;image.png&quot;,
        scaleGridTop=&quot;5&quot;, scaleGridBottom=&quot;15&quot;,
        scaleGridLeft=&quot;5&quot;, scaleGridRight=&quot;15&quot;)]
    public static const imageClass:Class;

    [Embed(source=&quot;lib.swf&quot;, symbol=&quot;symbol&quot;)]
    public static const symbolClass:Class;

    [Embed(source=&quot;lib.swf&quot;, symbol=&quot;symbol2&quot;)]
    public static const symbol2Class:Class;
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Image width=&quot;100&quot; height=&quot;200&quot; source=&quot;{imageClass}&quot;
    maintainAspectRatio=&quot;false&quot;/&gt;
&lt;mx:Image width=&quot;100&quot; height=&quot;200&quot; source=&quot;{symbolClass}&quot;
    maintainAspectRatio=&quot;false&quot;/&gt;
&lt;mx:Image width=&quot;100&quot; height=&quot;200&quot; source=&quot;{symbol2Class}&quot;
    maintainAspectRatio=&quot;false&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>6. result from flex</p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/9slice_result_flex.png"><img src="http://blog.yoz.sk/wp-content/uploads/9slice_result_flex.png" alt="9slice_result_flex" title="9slice_result_flex" width="357" height="231" class="alignnone size-full wp-image-652" /></a></p>
<p>gSkinner released <a href="http://www.gskinner.com/blog/archives/2010/04/bitmapslice9_sc.html">BitmapSlice9 command for Flash Pro</a>. It makes all this happen by one click.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/11/9-slice-scale-for-bitmaps-in-flash-no-hacks/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Bitmap, BitmapData, ByteArray&#8230;</title>
		<link>http://blog.yoz.sk/2009/10/bitmap-bitmapdata-bytearray/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bitmap-bitmapdata-bytearray</link>
		<comments>http://blog.yoz.sk/2009/10/bitmap-bitmapdata-bytearray/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 12:26:40 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[converting]]></category>
		<category><![CDATA[DisplayObject]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[LoaderInfo]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[URLRequest]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=135</guid>
		<description><![CDATA[Lets see how to convert between Bitmap, BitmapData and ByteArray in few examples: DisplayObject to BitmapData BitmapData to Bitmap BitmapData to ByteArray URL (image) to ByteArray (asynchronous) URL (image) to BitmapData (asynchronous) ByteArray to BitmapData (asynchronous) DisplayObject to BitmapData. FYI DisplayObject is any visible object in flash (Sprite, MovieClip, Bitmap, UIComponent, Video etc&#8230;): BitmapData to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/bitmap_converting.png"><img src="http://blog.yoz.sk/wp-content/uploads/bitmap_converting-200x119.png" alt="bitmap_converting" title="bitmap_converting" width="200" height="119" class="alignleft size-medium wp-image-452" /></a></p>
<p>Lets see how to convert between Bitmap, BitmapData and ByteArray in few examples:</p>
<ul style="float:left;">
<li>DisplayObject to BitmapData</li>
<li>BitmapData to Bitmap</li>
<li>BitmapData to ByteArray</li>
<li>URL (image) to ByteArray (asynchronous)</li>
<li>URL (image) to BitmapData  (asynchronous) </li>
<li>ByteArray to BitmapData  (asynchronous) </li>
</ul>
<div style="clear:both;"></div>
<p><span id="more-135"></span></p>
<p>DisplayObject to BitmapData. FYI <a href="http://livedocs.adobe.com/flex/3/langref/flash/display/DisplayObject.html">DisplayObject is any visible object in flash</a> (Sprite, MovieClip, Bitmap, UIComponent, Video etc&#8230;):</p>
<pre class="brush: as3; title: ; notranslate">import flash.display.BitmapData;
var bitmapData:BitmapData = new BitmapData(button.width, button.height, false, 0xFFFFFF);
bitmapData.draw(button);
// result: bitmapData</pre>
<p>BitmapData to Bitmap:</p>
<pre class="brush: as3; title: ; notranslate">import flash.display.Bitmap;
var bitmap:Bitmap = new Bitmap(bitmapData);
// result: bitmap</pre>
<p>BitmapData to ByteArray. Requires jpeg / png or any other encoder. <a href="http://blog.yoz.sk/2009/10/actionscript-3-encoding-jpeg/">Read more about JPEG encoding here</a>:</p>
<pre class="brush: as3; title: ; notranslate">import mx.graphics.codec.JPEGEncoder;
import flash.utils.ByteArray;
var encoder:JPEGEncoder = new JPEGEncoder(90);
var byteArray:ByteArray = encoder.encode(bitmapData));
// result: byteArray</pre>
<p>URL (image) to ByteArray. Asynchronous operation:</p>
<pre class="brush: as3; title: ; notranslate">import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.utils.ByteArray;

var loader:Loader = new Loader();
loader.load(new URLRequest(&quot;banner1.jpg&quot;));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);

private function loaderComplete(event:Event):void
{
    var loaderInfo:LoaderInfo = LoaderInfo(event.target);
    var byteArray:ByteArray = loaderInfo.bytes;
    // result: byteArray
}</pre>
<p>URL (image) to BitmapData. Asynchronous operation:</p>
<pre class="brush: as3; title: ; notranslate">import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.BitmapData;

var loader:Loader = new Loader();
loader.load(new URLRequest(&quot;banner1.jpg&quot;));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);

private function loaderComplete(event:Event):void
{
    var loaderInfo:LoaderInfo = LoaderInfo(event.target);
    var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height, false, 0xFFFFFF);
    bitmapData.draw(loaderInfo.loader);
    // result: bitmapData
}</pre>
<p>ByteArray to BitmapData. Asynchronous operation:</p>
<pre class="brush: as3; title: ; notranslate">import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.display.BitmapData;

var loader:Loader = new Loader();
loader.loadBytes(byteArray);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);

private function loaderComplete(event:Event):void
{
    var loaderInfo:LoaderInfo = LoaderInfo(event.target);
    var bitmapData:BitmapData = new BitmapData(loaderInfo.width, loaderInfo.height, false, 0xFFFFFF);
    bitmapData.draw(loaderInfo.loader);
    // result: bitmapData
}</pre>
<p><a href="http://www.bytearray.org/?p=1089">Synchronous JPEG ByteArray to BitmapData can be found here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/bitmap-bitmapdata-bytearray/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Embedding assets wisely</title>
		<link>http://blog.yoz.sk/2009/10/embedding-assets-wisely/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=embedding-assets-wisely</link>
		<comments>http://blog.yoz.sk/2009/10/embedding-assets-wisely/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 08:16:07 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[asset]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[SpriteAsset]]></category>
		<category><![CDATA[symbol]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=302</guid>
		<description><![CDATA[You can embed various types of assets in your Adobe Flex applications (.jpeg, .png, .swf, .mp3, .svg, .ttf &#8230;). Embedded assets are compiled into the SWF file of your Flex application. They are not loaded at run time and you do not have to deploy the original asset files with your application. Read more about [...]]]></description>
			<content:encoded><![CDATA[<p>You can embed various types of assets in your Adobe Flex applications (.jpeg, .png, .swf, .mp3, .svg, .ttf &#8230;). Embedded assets are compiled into the SWF file of your Flex application. They are not loaded at run time and you do not have to deploy the original asset files with your application. Read more about embedding assets <a href="http://www.adobe.com/devnet/flex/quickstart/embedding_assets/">on Adobe</a>.</p>
<p>Basics first. How to make your symbol from Flash library visible for Flex (see images on the bottom of the artice):</p>
<ul>
<li>1. Create your symbol and linkage (library (Ctrl+L) / {your symbol} / Linkage&#8230;).</li>
<li>2. Linkage Properties, set your class name that will be used in [Embed] meta.</li>
<li>3. Export .swf file and make Assets.as.</li>
</ul>
<p><span id="more-302"></span></p>
<p>It is very handy to use central assets class. This is how I make my assets accessible in Flex application:</p>
<pre class="brush: as3; title: ; notranslate">package
{
    import mx.core.SpriteAsset;

    public class Assets extends Object
    {
        // change/to/your/uber/cool/path/and/filename.whatsoever
        // you can also embed graphic files (.jpeg, .png, )
        [Embed(source=&quot;../libs/assets.swf#symbol1&quot;)]
        public static const symbol1Class:Class;
        public static const symbol1SpriteAsset:SpriteAsset = new symbol1Class();

        [Embed(source=&quot;../libs/assets.swf&quot;, symbol=&quot;symbol2&quot;)]
        public static const symbol2Class:Class;

        // embedding Bitmap
        [Embed(source=&quot;../libs/image.png&quot;)]
        public static const imageClass:Class;
        public static const imageBitmap:Bitmap = new imageClass();

        public function Assets()
        {
            super();
        }
    }
}</pre>
<p>There are two ways how to ask for your symbol from .swf library &#8211; <em>1. source=&#8221;&#8230;#symbol1&#8243;</em> or <em>2. source=&#8221;&#8230;&#8221; symbol=&#8221;symbol2&#8243;</em>. Symbol name is whatever you set in Linkage Properties Class in Flash (not symbol name in library!).</p>
<p>Usage example:</p>
<pre class="brush: as3; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;horizontal&quot; applicationComplete=&quot;init()&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    import Assets;

    private function init():void
    {
        container1.setStyle(&quot;backgroundImage&quot;, Assets.symbol1Class);
        container2.setStyle(&quot;backgroundImage&quot;, Assets.symbol2Class);
        container3.addChild(Assets.symbol1SpriteAsset);
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Box id=&quot;container1&quot; width=&quot;100&quot; height=&quot;100&quot;/&gt;
&lt;mx:Box id=&quot;container2&quot; width=&quot;100&quot; height=&quot;100&quot;/&gt;
&lt;mx:UIComponent id=&quot;container3&quot; width=&quot;100&quot; height=&quot;100&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>Embedding proccess and example result in images:</p>
<p><div id="attachment_305" class="wp-caption alignnone" style="width: 210px"><a href="http://blog.yoz.sk/wp-content/uploads/how_to_linkage_symbol.png"><img src="http://blog.yoz.sk/wp-content/uploads/how_to_linkage_symbol-200x157.png" alt="Flash linkage symbol" title="how_to_linkage_symbol" width="200" height="157" class="size-medium wp-image-305" /></a><p class="wp-caption-text">Flash linkage symbol</p></div><br />
<div id="attachment_306" class="wp-caption alignnone" style="width: 210px"><a href="http://blog.yoz.sk/wp-content/uploads/linkage_properties.png"><img src="http://blog.yoz.sk/wp-content/uploads/linkage_properties-200x158.png" alt="Flash linkage properties" title="linkage_properties" width="200" height="158" class="size-medium wp-image-306" /></a><p class="wp-caption-text">Flash linkage properties</p></div><br />
<div id="attachment_307" class="wp-caption alignnone" style="width: 210px"><a href="http://blog.yoz.sk/wp-content/uploads/embeded.png"><img src="http://blog.yoz.sk/wp-content/uploads/embeded-200x125.png" alt="Flex embedded symbols" title="embeded" width="200" height="125" class="size-medium wp-image-307" /></a><p class="wp-caption-text">Flex embedded symbols</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/embedding-assets-wisely/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ActionScript 3 encoding JPEG, alchemy</title>
		<link>http://blog.yoz.sk/2009/10/actionscript-3-encoding-jpeg/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=actionscript-3-encoding-jpeg</link>
		<comments>http://blog.yoz.sk/2009/10/actionscript-3-encoding-jpeg/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 11:53:05 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[alchemy]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[converting]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[jpeg]]></category>
		<category><![CDATA[JPEGEncoder]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=136</guid>
		<description><![CDATA[Lets assume you want to save an image (or any DisplayObject) from flash to disk, or upload to facebook etc. What you need is to encode your BitmapData into an Jpeg and send ByteArray raw data to be saved/uploaded. There are few ways how to do it. First, you can use original adobe mx.graphics.codec.JPEGEncoder. Sadly, [...]]]></description>
			<content:encoded><![CDATA[<p>Lets assume you want to save an image (or any DisplayObject) from flash to disk, or upload to facebook etc. What you need is to encode your BitmapData into an Jpeg and send ByteArray raw data to be saved/uploaded. There are few ways how to do it.</p>
<p>First, you can use original adobe mx.graphics.codec.JPEGEncoder. Sadly, this encoder is the slowest. There were attemps to make it faster by otpimizing code by <a href="http://www.bytearray.org/">bytearray.org</a>, that resulted into two times faster <a href='http://classes.yoz.sk/org/bytearray/images/JPEGEncoder.as'>org.bytearray.images.JPEGEncoder</a>. Usage is pretty simple:</p>
<p><span id="more-136"></span></p>
<pre class="brush: as3; title: ; notranslate">import org.bytearray.JPEGEncoder;

function encode():ByteArray
{
    var bitmapData:BitmapData = new BitmapData(this.width, this.height, false);
    bitmapData.draw(this);
    var encoder:JPEGEncoder = new JPEGEncoder(80);
    return encoder.encode(bitmapData);
}</pre>
<p>But not fast enough <img src='http://blog.yoz.sk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . Since Flash Player 10 introduced <a href="http://labs.adobe.com/technologies/alchemy/">alchemy</a> (compiled C and C++ code within flash apps), it was possible to use <a href='http://classes.yoz.sk/jpegencoder.swc'>optimized C++ encoder to do the work</a>. Encoding time is more than 30 times faster than the original JPEGEncoder, pretty cool huh? Code looks like this</p>
<pre class="brush: as3; title: ; notranslate">import cmodule.jpegencoder.CLibInit;

function encode():ByteArray
{
    var bitmapData:BitmapData = new BitmapData(this.width, this.height, false);
    bitmapData.draw(this);
    var init:CLibInit = new CLibInit();
    var lib:Object = init.init();
    var byteArray:ByteArray = new ByteArray();
    var byteArrayOut:ByteArray = new ByteArray();
    byteArray = bitmapData.getPixels(bitmapData.rect);
    byteArray.position = 0;
    lib.encode(byteArray, byteArrayOut, bitmapData.width, bitmapData.height, 80);
    return byteArrayOut;
}</pre>
<p>You can also run your encoding in asynchronous mode&#8230; Read more and see tests here:</p>
<ul>
<li><a href="http://segfaultlabs.com/blog/post/asynchronous-jpeg-encoding">Alchemy &#8211; asynchronous jpeg encoding</a></li>
<li><a href="http://www.websector.de/blog/2009/06/21/speed-up-jpeg-encoding-using-alchemy/">Speed up JPEG encoding using Alchemy</a></li>
<li><a href="http://labs.adobe.com/technologies/alchemy/">Alchemy technology</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/actionscript-3-encoding-jpeg/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

