<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Eternal Coding - HTML5 / Windows / Kinect / 3D development</title><link>http://blogs.msdn.com/b/eternalcoding/</link><description>var life = new[] {&amp;quot;eat&amp;quot;, &amp;quot;sleep&amp;quot;, &amp;quot;code&amp;quot;}</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Benchmarking a HTML5 game: HTML5 Potatoes Gaming Bench</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/05/21/benchmarking-a-html5-game-html5-potatoes-gaming-bench.aspx</link><pubDate>Tue, 21 May 2013 10:48:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10420275</guid><dc:creator>David Catuhe</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10420275</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10420275</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/05/21/benchmarking-a-html5-game-html5-potatoes-gaming-bench.aspx#comments</comments><description>&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7103.HTML5Potatoes_5F00_22E5699B.png"&gt;&lt;img title="HTML5 Potatoes logo" style="float: right; display: inline;" border="0" alt="HTML5 Potatoes logo" align="right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8171.HTML5Potatoes_5F00_thumb_5F00_5C880385.png" width="240" height="136" /&gt;&lt;/a&gt;  &lt;p&gt;A few weeks ago, my friend David Rousset wrote an excellent article about &lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/04/26/html5-gaming-benchmarking-sprites-animations-on-your-targeted-devices-amp-browsers.aspx"&gt;“benchmarking your sprites animations to target all devices &amp;amp; browsers”&lt;/a&gt;. This article used a benchmark framework called “HTML5 Potatoes Gaming Bench” to obtain a consistent &lt;strong&gt;scoring&lt;/strong&gt; for various sprites tests.&lt;/p&gt;  &lt;p&gt;I will try to explain you how we built this framework and the decision we made to make it representative of the effective performance of the tested hardware and browser.&lt;/p&gt;  &lt;p&gt;You will see that this framework can be used to measure any scenarios you want to benchmark for your own games.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8130.image_5F00_17F8704D.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4857.image_5F00_thumb_5F00_5C58618C.png" width="640" height="438" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;The delta time&lt;/h1&gt;  &lt;p&gt;First of all, we have to talk about the delta time. Indeed, when you wrote games or any resources intensive applications, the principle is always the same: you must have a render loop where the display is done (sprites, effects, etc.). &lt;/p&gt;  &lt;p&gt;The user will have a feeling of great performance when the elapsed time between two rendered frames is near the well known target of &lt;strong&gt;(1000 / 60)ms (about 16ms).&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;So targeting 60 frames per second will be the duty of any game developer: No one is prone to experience lag or slowness in the responsiveness of their game.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Actually, the delta time can be defined as &lt;strong&gt;the elapsed time between two passes in the render loop&lt;/strong&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To compute this value, you just have to store the current date() when you start a new frame and subtract the previous stored date(). The result is the number of milliseconds between the two frames:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;previousDate;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;computeDeltaTime = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!previousDate) {
        previousDate = Date.now();
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;0;
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;currentDate = Date.now();
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delta = currentDate - previousDate;
    previousDate = currentDate;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delta;
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Calling this function just before rendering a new frame will allow us to determine the current delta time:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;renderLoop = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;while &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(renderInProgress) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;deltaTime = computeDeltaTime();
        
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// render your frame here
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}
};&lt;/span&gt;&lt;/pre&gt;

&lt;h1&gt;Render loop&lt;/h1&gt;

&lt;p&gt;Actually, the render loop cannot be a &lt;em&gt;while(true){}&lt;/em&gt; function. Indeed, JavaScript is mono-threaded so looping in a function will just block entirely your browser.&lt;/p&gt;

&lt;p&gt;So you must be called by the browser every time a frame is requested. To do so, the &lt;a href="http://www.w3.org/2010/webperf/"&gt;W3C&lt;/a&gt; introduced a new API called &lt;strong&gt;requestAnimationFrame&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This API tells the browser that you wish to perform an animation and requests that the browser schedule a repaint of the window for the next animation frame. It also takes in account the visibility of the page in order to avoid unnecessary renders.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;requestAnimationFrame&lt;/strong&gt; is far better than a simple &lt;strong&gt;setTimeout&lt;/strong&gt; API because &lt;strong&gt;setTimeout&lt;/strong&gt; API can provide choppy animations and increase resource consumption by rendering not required frames.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the PERFECT place to render your new frame. And ovbiously this is the perfect place to evalute your delta time. (It is worth noting that &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; gives you a parameter indicating the time at which the function is scheduled to be called).&lt;/p&gt;

&lt;p&gt;So the new render loop looks like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;renderLoop = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;deltaTime = computeDeltaTime();

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// render your frame here
    
    // Schedule new frame
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;requestAnimationFrame(renderLoop);
};

&lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// First call
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;requestAnimationFrame(renderLoop);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Alas, the &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; API is not supported by every browser according to &lt;a href="http://www.caniuse.com"&gt;www.caniuse.com&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4705.image_5F00_13523FC6.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4721.image_5F00_thumb_5F00_192CE35F.png" width="953" height="383" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To prevent the benchmark for not working on every browser, we can use this small polyfill:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;POTATOES.Tools.queueNewFrame = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(func) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(window.requestAnimationFrame)
        window.requestAnimationFrame(func);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(window.msRequestAnimationFrame)
        window.msRequestAnimationFrame(func);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(window.webkitRequestAnimationFrame)
        window.webkitRequestAnimationFrame(func);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(window.mozRequestAnimationFrame)
        window.mozRequestAnimationFrame(func);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(window.oRequestAnimationFrame)
        window.oRequestAnimationFrame(func);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
        window.setTimeout(func, 16);
    }
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can note that the &lt;strong&gt;setTimeout&lt;/strong&gt; API is used as a fallback for the &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; API.&lt;/p&gt;

&lt;h1&gt;Measuring FPS&lt;/h1&gt;

&lt;p&gt;The benchmark need a value called FPS (standing for frames per second). Computing the FPS is an easy task when you have &lt;strong&gt;requestAnimationFrame&lt;/strong&gt; and the delta time.&lt;/p&gt;

&lt;p&gt;To do so, HTML5 Potatoes Gaming Bench uses a function called &lt;em&gt;handleMetrics&lt;/em&gt;. This function is responsible for computing the immediate FPS and the average FPS. The first one is just the FPS based on the delta time between the current frame and the previous one. The second one is the average of FPS for a given number of previous frames:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;fpsFrame = 20; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// fps window frame
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;fpsCap = 60;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;previousFramesDuration = [];

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;handleMetrics = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    previousFramesDuration.push(Date.now());

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(previousFramesDuration.length &amp;gt;= fpsFrame) {

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(previousFramesDuration.length &amp;gt; fpsFrame) {
            previousFramesDuration.splice(0, 1);
        }

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;avg = 0;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;id = 0; id &amp;lt; fpsFrame - 1; id++) {
            avg += previousFramesDuration[id + 1] - previousFramesDuration[id];
        }
        avg /= fpsFrame - 1;

        POTATOES.GamingBench.currentFPS = Math.min(fpsCap, 1000.0 / (&lt;br /&gt;                      previousFramesDuration[fpsFrame - 1] - previousFramesDuration[fpsFrame - 2]));
        POTATOES.GamingBench.averageFPS = Math.min(fpsCap, 1000.0 / avg);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    }
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    POTATOES.Tools.queueNewFrame(handleMetrics);
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To be sure the results are correct, I installed the &lt;a href="http://msdn.microsoft.com/en-us/performance/cc825801.aspx"&gt;Windows Performance Toolkit&lt;/a&gt; in order to compare the measures.&lt;/p&gt;

&lt;p&gt;For my tests I used these benches: &lt;a title="http://www.html5potatoes.com/gamingbench/index.htm" href="http://www.html5potatoes.com/gamingbench/index.htm"&gt;http://www.html5potatoes.com/gamingbench/index.htm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.html5potatoes.com/gamingbench/index.htm"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8322.image11_5F00_0A160485.png" width="632" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two tests are used:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Canvas pixels manipulations&lt;/strong&gt;&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Processing images with web workers&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
  &lt;br /&gt;The Windows Performance Analyser gave the following results:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3010.image_5F00_60528991.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2783.image_5F00_thumb_5F00_19F5237C.png" width="640" height="361" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that the first test runs between 25 and 30 frames per second. The second one runs almost at full speed.&lt;/p&gt;

&lt;p&gt;The good news is that the results computed by the Gaming Bench are similar:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3301.image_5F00_385F6465.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0272.image_5F00_thumb_5F00_5082CEC0.png" width="644" height="299" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4747.image_5F00_565D7259.png"&gt;&lt;img title="image" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2543.image_5F00_thumb_5F00_39081A8F.png" width="644" height="293" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second test is not at more than &lt;strong&gt;60fps&lt;/strong&gt; because we use requestAnimationFrame which prevents unnecessary renders.&lt;/p&gt;

&lt;p&gt;So we can consider that the measured values are consistent.&lt;/p&gt;

&lt;h1&gt;Using HTML5 Potatoes Gaming Bench&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;HTML5 Potatoes Gaming Bench&lt;/em&gt; is an open and free Framework that you can use freely &lt;img class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3323.wlEmoticon_2D00_smile_5F00_1331F42C.png" /&gt;&lt;/p&gt;

&lt;p&gt;You can download all the code used previously here: &lt;a href="http://www.html5potatoes.com/gamingbench/gamingbench.zip"&gt;http://www.html5potatoes.com/gamingbench/gamingbench.zip&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Gaming Bench was designed to provide an infrastructure to test whatever you want on a browser. So to add your own test on the gaming bench, you just have to create a Bench object with this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;tunnelBench = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;POTATOES.GamingBench.Bench(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;Canvas pixels manipulations&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;http://aka.ms/potatoes_tunnel&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(workbench) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Init
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;init(workbench, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.onInitCompleted);
    }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Run
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;render = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        POTATOES.Tools.queueNewFrame(renderingLoop);
    }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(workbench) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// End
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;render = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;            
    });

POTATOES.GamingBench.registerBench(tunnelBench);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You have to provide 3 functions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Init&lt;/em&gt;: This function is called once in order to create the DOM required by your test. It gives you the workbench parameter which is the DOM container where you can add your objects.&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;Run&lt;/em&gt;: This function is called to launch your test (this is where you can call the &lt;em&gt;queueNewFrame&lt;/em&gt; function)&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;End&lt;/em&gt;: This function is called to stop your render and eventually clean associated ressources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
  &lt;br /&gt;The &lt;em&gt;POTATOES.GamingBench.registerBench&lt;/em&gt; function is used to add your bench to the list of active benches.&lt;/p&gt;

&lt;p&gt;To run the complete Gaming Bench, you have to use this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Starting benchmark
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;POTATOES.GamingBench.start();&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you need to cancel it, just use this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;POTATOES.GamingBench.cancel();&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can also skip the current test and go to the next one:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;POTATOES.GamingBench.skipCurrent();&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Finally if you want to gather results, you have to use this kind of code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;POTATOES.GamingBench.onprocessended = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Generating the result list
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;score = 0;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; POTATOES.GamingBench.benches.length; index++) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bench = POTATOES.GamingBench.benches[index];
        score += bench.score;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;And that’s it! Feel free to take a look at the sample code to see how you can use the framework to extract all the infos you can need.&lt;/p&gt;

&lt;h1&gt;Understanding score&lt;/h1&gt;

&lt;p&gt;After running the complete Gaming Bench, you can analyse the score using a chart produced with &lt;a href="http://d3js.org/"&gt;d3.js&lt;/a&gt;. The score is computed by adding one point on every rendered frame. Obviously, you can modify this behavior for your own bench to take in account another metric. This is what David Rousset did for his own &lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/04/26/html5-gaming-benchmarking-sprites-animations-on-your-targeted-devices-amp-browsers.aspx"&gt;benches&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is a sample on how you can use details provided by the framework to compute a global fps:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;avgFps = 0;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; bench.stats.length; i++) {
    avgFps += bench.stats[i].y;
}

avgFps /= bench.stats.length;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;I really hope you will find this framework useful to help you create wonderful and efficient games!&lt;/p&gt;

&lt;h1&gt;Going further&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/04/26/html5-gaming-benchmarking-sprites-animations-on-your-targeted-devices-amp-browsers.aspx"&gt;HTML5 Gaming: benchmarking your sprites animations to target all devices &amp;amp; browsers&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;W3C performance working group: &lt;a title="http://www.w3.org/2010/webperf/" href="http://www.w3.org/2010/webperf/"&gt;http://www.w3.org/2010/webperf/&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx"&gt;Unleash the power of HTML 5 Canvas for gaming&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/09/20/using-web-workers-to-improve-performance-of-image-manipulation.aspx"&gt;Using Web Workers to improve performance of image manipulation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10420275" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML+5/">HTML 5</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/">Javascript</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Benchmark/">Benchmark</category></item><item><title>Using Visual Studio’s Javascript Memory Analysis tool to find memory leaks on your Windows 8 Javascript app</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/24/using-visual-studio-s-javascript-memory-analysis-tool-to-find-memory-leaks-on-your-windows-8-javascript-app.aspx</link><pubDate>Wed, 24 Apr 2013 08:24:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10413587</guid><dc:creator>David Catuhe</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10413587</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10413587</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/24/using-visual-studio-s-javascript-memory-analysis-tool-to-find-memory-leaks-on-your-windows-8-javascript-app.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;Javascript&lt;/strong&gt; is a wonderful language for developing Windows 8 apps. As a untyped, dynamic language, &lt;strong&gt;Javascript&lt;/strong&gt; is really flexible but sometimes if you are not careful you may leave some memory leaks in your code.&lt;/p&gt;  &lt;p&gt;But do not worry, &lt;strong&gt;Visual Studio&lt;/strong&gt; includes a great tool called &lt;strong&gt;Javascript Memory Analysis&lt;/strong&gt; in order to help you find out where the leaks are.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8204.image_5F00_32004984.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4643.image_5F00_thumb_5F00_2AE39DBD.png" width="722" height="415" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Using the Javascript Memory Analysis tool&lt;/h1&gt;  &lt;p&gt;This tool is available in the &lt;strong&gt;Debug&lt;/strong&gt; menu of your &lt;strong&gt;Visual Studio&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8787.image_5F00_55BE9280.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2818.image_5F00_thumb_5F00_057C3B00.png" width="868" height="186" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Launching the tool will launch your app and will show this screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1325.image_5F00_2048610C.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3808.image_5F00_thumb_5F00_5006098B.png" width="948" height="606" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The first part of the window is dedicated to the real-time monitoring of the memory used by the application:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8272.image_5F00_18BF8250.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6622.image_5F00_thumb_5F00_14490189.png" width="678" height="120" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Right after you can find a button (&lt;em&gt;Take Heap Snapshot&lt;/em&gt;) used to capture the instantaneous state of the memory heap (The control also indicates the size of the heap and the number of active objects):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0456.image_5F00_4CF3AB96.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6523.image_5F00_thumb_5F00_53A945CA.png" width="1056" height="680" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;By clicking on the heap size, a more detailed view is generated:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/7128.image_5F00_3C119857.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5732.image_5F00_thumb_5F00_2B99275C.png" width="864" height="575" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This view presents a sorted list of the objects by retained size, &lt;strong&gt;which means the objects consuming the most memory that are potentially easiest to free would be listed first.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For instance, in my app, I can see that the &lt;em&gt;UrzaGatherer&lt;/em&gt; object retains almost &lt;strong&gt;60 MB&lt;/strong&gt; (which is normal because it handles a huge list of &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/20/how-to-cook-a-windows-8-application-with-html5-javascrip-css3-rtm-version.aspx"&gt;cards&lt;/a&gt;):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5224.image_5F00_301238D4.png"&gt;&lt;img title="image" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0434.image_5F00_thumb_5F00_3895981E.png" width="1022" height="579" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The view can also display:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;a list of types sorted by occurrence count &lt;/li&gt;    &lt;li&gt;a list of root objects (from the garbage collector point of view)&lt;/li&gt;    &lt;li&gt;a list of &lt;strong&gt;DOM&lt;/strong&gt; objects sorted by retained size&lt;/li&gt;    &lt;li&gt;a list of &lt;strong&gt;WinRT&lt;/strong&gt; objects sorted by retained size&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;   &lt;br /&gt;All of these views can potentially help you find &lt;strong&gt;inconsistent&lt;/strong&gt; memory usage.&lt;/p&gt;  &lt;h1&gt;Comparing snapshots&lt;/h1&gt;  &lt;p&gt;Each time you click on &lt;em&gt;Take Heap Snapshot &lt;/em&gt;button, the system generates a new dump of the heap for further analysis. Furthermore, each snapshot indicates the difference of the heap size and objects count against previous snapshot.&lt;/p&gt;  &lt;p&gt;This is the &lt;strong&gt;key&lt;/strong&gt; for finding memory leaks.&lt;/p&gt;  &lt;p&gt;For instance, in my app, I will take a first snapshot, navigate to a given page, then go back to home page and finally take a second snapshot. Doing this I will be able to see if the given page produces memory leaks.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2313.image_5F00_3D0EA996.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0841.image_5F00_thumb_5F00_411B8819.png" width="664" height="325" /&gt;&lt;/a&gt;&lt;/p&gt;  We can see here that between the two snapshots, the heap size has grown of &lt;strong&gt;6.12 MB&lt;/strong&gt; and more than &lt;strong&gt;53k &lt;/strong&gt;objects were generated and still alive.&amp;#160;&amp;#160; &lt;p&gt;By clicking on the heap size difference (+6.12 MB), you can view a detail of the heap size compared to previous snapshot:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6523.image_5F00_16CEE0EF.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5633.image_5F00_thumb_5F00_0892F8B0.png" width="1024" height="293" /&gt;&lt;/a&gt;    &lt;br /&gt;The Dominators view indicates that new objects remain when we come back to the home page. You can use this view to identify unwanted objects.&lt;/p&gt;  &lt;p&gt;In my case, the first line seems suspicious. By right-clicking on it, I can go to the Root view to see which function retains my objects:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8666.image_5F00_485F6FE6.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4137.image_5F00_thumb_5F00_60F19DE7.png" width="1024" height="415" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; We can see that the object is retained by a function called &lt;em&gt;ImportFromTappedOut&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;After looking for this function in my code, it turns out that this function is a global function which takes a&amp;#160; function as parameter:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;I&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;mportFromTappedOut = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(deckName, &lt;strong&gt;&lt;u&gt;custom&lt;/u&gt;&lt;/strong&gt;) {&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;em&gt;custom &lt;/em&gt;parameter is used by this function to call some specific user code. The main problem is that because the &lt;em&gt;ImportFromTappedOut&lt;/em&gt; is a global function it will retain all the code referenced by the function affected to the &lt;em&gt;custom&lt;/em&gt; parameter and in my case I used an anonymous function that references a lot of local DOM objects:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt; Tools.ImportFromTappedOut(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
     &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;select = document.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#addToDeck&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
     &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;count = document.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#addToDeckCount&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).value;

     listView.selection.getItems().then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(items) {
         appBar.hide();
         appBar.sticky = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
         listView.selection.clear();&lt;br /&gt;&lt;em&gt;…code continue…&lt;/em&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And this exactly the problem described by the tool:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5633.image_5F00_1DA92678.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0743.image_5F00_thumb_5F00_222237F0.png" width="647" height="125" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The solution is easy: I just have to call &lt;em&gt;importFromTappedOut&lt;/em&gt; with a null function when I leave the page in order to allow the garbage collector to collect all retained objects (1.25 MB here).&lt;/p&gt;

&lt;p&gt;I clearly encourage you to use this tool to detect and eradicate memory leaks. It is simple and really powerful and can help you get rid of memory problems.&lt;/p&gt;

&lt;h1&gt;More about the tool&lt;/h1&gt;

&lt;p&gt;Others articles you may find useful:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/visualstudio/archive/2013/02/04/10388914.aspx"&gt;JavaScript memory analysis for Windows Store apps in Visual Studio 2012&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/11/15/optimizing-javascript-windows-8-application-using-the-visual-studio-performance-analysis-tool-profiler.aspx"&gt;Optimizing JavaScript Windows 8 application: Using the Visual Studio performance analysis tool (profiler)&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/20/how-to-cook-a-windows-8-application-with-html5-javascrip-css3-rtm-version.aspx"&gt;How to cook a Windows 8 application with HTML5/Javascript/CSS3&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx"&gt;Unleash the power of HTML 5 Canvas for gaming&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;[French]&lt;a title="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=f721312a-cc92-4599-8795-cfe07d5c0bb4" href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=f721312a-cc92-4599-8795-cfe07d5c0bb4"&gt;http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=f721312a-cc92-4599-8795-cfe07d5c0bb4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10413587" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML+5/">HTML 5</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/">Javascript</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/">Windows 8</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/">WinRT</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Visual+Studio/">Visual Studio</category></item><item><title>Now with Javascript: Reading PDF and XPS on your Windows 8 application using WinRT</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/22/now-with-javascript-reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx</link><pubDate>Mon, 22 Apr 2013 07:10:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10412951</guid><dc:creator>David Catuhe</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10412951</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10412951</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/22/now-with-javascript-reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx#comments</comments><description>&lt;p&gt;Following my previous article on “&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/15/reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx"&gt;Reading PDF and XPS on your Windows 8 application using WinRT&lt;/a&gt;”, I would like to share with you the same example but with &lt;strong&gt;Javascript&lt;/strong&gt; code.&lt;/p&gt;  &lt;!--more--&gt;    &lt;p&gt;Many of you sent me a mail to get this code, so feel free to grab it here (&lt;em&gt;I would like to thank Mehdi Lahlou for his original version&lt;/em&gt;):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.catuhe.com/msdn/js.PDFReader.zip"&gt;http://www.catuhe.com/msdn/js.PDFReader.zip&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The principle is the &lt;strong&gt;same&lt;/strong&gt; as for C#: I use a &lt;em&gt;FlipView&lt;/em&gt; control that uses a custom template to generate.&lt;/p&gt;  &lt;p&gt;The &lt;em&gt;FlipView&lt;/em&gt; is nothing but a standard &lt;em&gt;WinJS&lt;/em&gt; control:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.UI.FlipView&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;flipView&amp;quot;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To open the PDF file, we can use the following code (standard &lt;em&gt;WinRT&lt;/em&gt; code):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;openPDF: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(filename) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(filename).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(file) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage.FileIO.readBufferAsync(file).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(fileBuffer) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;MuPDFWinRT.Document.create(fileBuffer, MuPDFWinRT.DocumentType.pdf, &lt;br /&gt;                               Windows.Graphics.Display.DisplayProperties.logicalDpi);
        });
    });
},&lt;/span&gt;&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;p&gt;Please note that the MuPDFWinRT component used here is strictly the same as the one used by C#&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once the PDF is opened we can configure the &lt;em&gt;FlipView&lt;/em&gt; using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.openPDF(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;test.pdf&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(pdfDocument) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;array = [];
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; pdfDocument.pageCount; i++) {
        array.push(i);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;dataList = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;WinJS.Binding.List(array);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;flipViewDOM = document.getElementById(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;flipView&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;flipView = flipViewDOM.winControl;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width = flipViewDOM.clientWidth;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height = flipViewDOM.clientHeight;
    
    flipView.itemDataSource = dataList.dataSource;
    flipView.itemTemplate = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(itemPromise) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;itemPromise.then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(item) {
            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// root element for the item
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvas = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;canvas&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            
            canvas.style.width = width;
            canvas.style.height = height;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvasContext = canvas.getContext(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            that.drawPage(pdfDocument, canvasContext, item.index);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvas;
        });
    });
});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Each page will be generated using a canvas stretched to fill the &lt;em&gt;FlipView&lt;/em&gt;. Each canvas is then filled using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;drawPage: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(pdfDocument, canvasContext, index) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;size = pdfDocument.getPageSize(index);

    canvasContext.canvas.width = size.x;
    canvasContext.canvas.height = size.y;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData = canvasContext.createImageData(size.x, size.y);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Int32Array(size.x * size.y);

    pdfDocument.drawPage(index, current, 0, 0, size.x, size.y, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// from  ARGB to ABGR
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; current.length; i++) {

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;val = current[i];

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cursor = i * 4;

        imageData.data[cursor] = (val &amp;gt;&amp;gt; 16) &amp;amp; 0xFF; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;//r
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData.data[cursor + 1] = (val &amp;gt;&amp;gt; 8) &amp;amp; 0xFF; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;//g
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData.data[cursor + 2] = val &amp;amp; 0xFF; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;//b
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;imageData.data[cursor + 3] = 255; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// a
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}            
    canvasContext.putImageData(imageData, 0, 0);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Using &lt;em&gt;pdfDocument.drawPage&lt;/em&gt;, you can fill the image data object created by the canvas. You must then invert pixel color components to switch from ARGB to ABGR and finally paste the result Inside the canvas.&lt;/p&gt;

&lt;p&gt;And voila! &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10412951" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/">Javascript</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/">Windows 8</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/PDF/">PDF</category></item><item><title>Reading PDF and XPS on your Windows 8 application using WinRT</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/15/reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx</link><pubDate>Mon, 15 Apr 2013 09:20:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10411030</guid><dc:creator>David Catuhe</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10411030</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10411030</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/15/reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt; and &lt;strong&gt;XPS&lt;/strong&gt; file formats are widely used across the world and you could need one day to display them inside your &lt;img style="float: right; display: inline;" align="right" src="http://ts4.mm.bing.net/th?id=H.4786059119429635&amp;amp;pid=1.7&amp;amp;w=180&amp;amp;h=176&amp;amp;c=7&amp;amp;rs=1" width="94" height="92" /&gt;application.&lt;/p&gt;  &lt;p&gt;Today I would like to share with you a simple way to do so by using an open source solution: &lt;a href="http://mupdf.com/"&gt;&lt;strong&gt;MuPDF&lt;/strong&gt;&lt;/a&gt; (a multiplatform lightweight PDF and XPS viewer).&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;MuPDF&lt;/strong&gt; is already working on a &lt;strong&gt;WinRT&lt;/strong&gt; solution you can grab on this GIT repo: &lt;a title="http://git.ghostscript.com/?p=user/mvrhel/mupdf.git;a=summary" href="http://git.ghostscript.com/?p=user/mvrhel/mupdf.git;a=summary"&gt;http://git.ghostscript.com/?p=user/mvrhel/mupdf.git;a=summary&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;I also used the work of &lt;strong&gt;&lt;a href="https://github.com/libreliodev/windows8"&gt;Libreliodev&lt;/a&gt;&lt;/strong&gt; and especially their advanced port of &lt;strong&gt;MuPDF&lt;/strong&gt; for &lt;strong&gt;WinRT&lt;/strong&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The result is a simple but really useful &lt;em&gt;Windows 8 Modern UI&lt;/em&gt; app that is able to display a &lt;strong&gt;PDF&lt;/strong&gt;/&lt;strong&gt;XPS&lt;/strong&gt; file: &lt;a href="http://www.catuhe.com/msdn/pdfreader.zip"&gt;http://www.catuhe.com/msdn/pdfreader.zip&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/pdfreader2.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/pdfreader2.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;  &lt;!--more--&gt;  &lt;p&gt;The solution is based on two projects:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;MuPDF.winRT&lt;/strong&gt;: a C++/CX &lt;strong&gt;WinRT&lt;/strong&gt; component built upon &lt;strong&gt;MuPDF&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;PDFReader&lt;/strong&gt;: A C#XAML project that used the &lt;strong&gt;WinRT&lt;/strong&gt; component to display a &lt;strong&gt;PDF&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;For this article I created a C#/XAML application. But because MuPDF.winRT is a WinRT component, you can also use it from a &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/04/22/now-with-javascript-reading-pdf-and-xps-on-your-windows-8-application-using-winrt.aspx"&gt;HTML5/CSS3/Javascript app&lt;/a&gt;!&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Using the &lt;strong&gt;WinRT&lt;/strong&gt; component, you just have to use the following line to create a &lt;em&gt;Document&lt;/em&gt; (which is the class used to interact with a &lt;strong&gt;PDF &lt;/strong&gt;or a &lt;strong&gt;XPS&lt;/strong&gt;):&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;pdfDocument = &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Document&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Create(readBuffer, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DocumentType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.PDF, (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)Windows.Graphics.Display.&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DisplayProperties&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.LogicalDpi);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To draw a page, you just have to use the previous &lt;em&gt;pdfDocument&lt;/em&gt; object and call the &lt;em&gt;DrawPage&lt;/em&gt; method:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;pdfDocument.DrawPage(PageNumber, buf, 0, 0, width, height, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This method draws a given page inside a &lt;em&gt;IBuffer&lt;/em&gt;. To create it you just have to instantiate a &lt;em&gt;WriteableBitmap &lt;/em&gt;and the inner &lt;em&gt;PixelBuffer&lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;size = Document.GetPageSize(PageNumber);
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)(size.X * ZoomFactor);
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)(size.Y * ZoomFactor);

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;image = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;WriteableBitmap&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(width, height);
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IBuffer &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;buf = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Buffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(image.PixelBuffer.Capacity);
buf.Length = image.PixelBuffer.Length;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The buffer is then copied back to the &lt;em&gt;WriteableBitmap&lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;stream = buf.AsStream())
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;stream.CopyToAsync(image.PixelBuffer.AsStream());
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And finally the result is displayed on screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2671.image_5F00_38284D46.png"&gt;&lt;u&gt;&lt;/u&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6472.image_5F00_thumb_5F00_0D749489.png" width="640" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can even display two pages on the same image:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Task&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(() =&amp;gt; pdfDocument.DrawFirtPageConcurrent(PageNumber, buf, width, height));
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Task&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(() =&amp;gt; pdfDocument.DrawSecondPageConcurrent(PageNumber + 1, buf, width, height));&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4010.image_5F00_4EFCFE86.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4722.image_5F00_thumb_5F00_6C968B98.png" width="640" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using the mouse or the touch you can obviously navigate inside the document or zoom on pages. And with the power of vectorized PDF, you will always have the best display quality:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1777.image11_5F00_35A95E4C.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1108.image11_5F00_thumb_5F00_699890A3.png" width="640" height="398" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="center"&gt;&lt;em&gt;Optical zoom (bitmap based)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8524.image14_5F00_7382A370.png"&gt;&lt;img title="image" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5383.image14_5F00_thumb_5F00_41460BF7.png" width="640" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="center"&gt;&lt;em&gt;Vectorized zoom&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To display these images, I used a simple FlipView so that I do not have to bother about gestures. The &lt;em&gt;DataTemplate&lt;/em&gt; used for every page is based on a &lt;em&gt;ScrollViewer&lt;/em&gt; in order to automaticaly handle zoom in and zoom out:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Name&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;flipView&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView.ItemTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;DataTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;ScrollViewer
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;ZoomMode&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Enabled&amp;quot; 
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalScrollMode&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;VerticalScrollMode&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;VerticalSnapPointsType&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;None&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalSnapPointsType&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;None&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalScrollBarVisibility&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;VerticalScrollBarVisibility&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Auto&amp;quot;
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;MinZoomFactor&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;1&amp;quot;            
                &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;MaxZoomFactor&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;4&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Image &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Source&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Binding &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Image&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Width&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Binding &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Width&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Height&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;Binding &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Height&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;}&amp;quot; &lt;br /&gt;                       &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Stretch&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Uniform&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;Center&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;Margin&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;0&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;ScrollViewer&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;DataTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView.ItemTemplate&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;FlipView&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Simple, isn’t it ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10411030" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/">Windows 8</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/">WinRT</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/PDF/">PDF</category></item><item><title>Faites partie du futur Instagram ou Facebook :)</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/10/faites-partie-du-futur-instagram-ou-facebook.aspx</link><pubDate>Wed, 10 Apr 2013 11:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10409951</guid><dc:creator>David Catuhe</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10409951</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10409951</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/04/10/faites-partie-du-futur-instagram-ou-facebook.aspx#comments</comments><description>&lt;p&gt;&lt;span class="userContent"&gt;Chers d&amp;eacute;veloppeurs, &amp;nbsp;je vous propose d'inviter ceux d'entre vous qui sont int&amp;eacute;ress&amp;eacute;s &amp;agrave; une apr&amp;egrave;s-midi de rencontres avec des dipl&amp;ocirc;m&amp;eacute;s de l'Ecole Sup&amp;eacute;rieure de Commerce de Paris.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Ces dipl&amp;ocirc;m&amp;eacute;s ont mont&amp;eacute; des projets, trouv&amp;eacute; et mis en place le design, fais le business plan, r&amp;eacute;alis&amp;eacute; les &amp;eacute;tudes de march&amp;eacute;s et parfois m&amp;ecirc;me commenc&amp;eacute; le marketing.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: x-large;"&gt;Il ne leur manque que &lt;strong&gt;VOUS :)&lt;span class="userContent"&gt;&lt;img style="float: right; max-width: 550px;" src="http://blog.psychopium.com/wp-content/uploads/2012/04/reussite.jpg" alt="" width="332" height="233" border="0" /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; Que vous soyez motiv&amp;eacute;s pour partager votre temps perso avec eux ou que vous ayez envie de rejoindre le projet en tant que &lt;strong&gt;CTO&lt;/strong&gt;, venez assister &amp;agrave; leurs pitchs et faites vos courses.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Si vous &amp;ecirc;tes int&amp;eacute;ress&amp;eacute;s, envoyez moi un &lt;a href="mailto:davca@microsoft.com"&gt;mail&lt;/a&gt;. Le pitch aura lieu le 18/04 &amp;agrave; &lt;a href="http://spark.microsoft.fr"&gt;Spark&lt;/a&gt; en mode "cosy".&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10409951" width="1" height="1"&gt;</description></item><item><title>WinRT component: How to generate a GUID?</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/25/winrt-component-how-to-generate-a-guid.aspx</link><pubDate>Mon, 25 Mar 2013 13:39:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10405089</guid><dc:creator>David Catuhe</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10405089</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10405089</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/25/winrt-component-how-to-generate-a-guid.aspx#comments</comments><description>&lt;p&gt;For your Windows 8 applications, you may need to generate a &lt;strong&gt;unique&lt;/strong&gt; identifier (for instance, if you want to uniquely identify your users).&lt;/p&gt;  &lt;p&gt;To do so, here is a small C++ WinRT component (I decided not to use C# to make the component light-weighted because it is pure native code and so you do not need to load the CLR to use it).&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#pragma once
#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Objbase.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;UrzaBox
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public ref class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Tools &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sealed
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
        Tools();

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;static &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;String&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ GetNewID()
        {
            &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;result;
            &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = CoCreateGuid(&amp;amp;result);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
            {
                &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Guid &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;gd(result);
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;gd.ToString();
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;throw &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Exception&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::CreateException(hr);
        }
    };
}&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10405089" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/">WinRT</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/GUID/">GUID</category></item><item><title>Create a custom user control using JavaScript and WinJS for Windows 8</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/19/create-a-custom-user-control-using-javascript-and-winjs-for-windows-8.aspx</link><pubDate>Tue, 19 Mar 2013 13:08:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10403465</guid><dc:creator>David Catuhe</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10403465</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10403465</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/19/create-a-custom-user-control-using-javascript-and-winjs-for-windows-8.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3782.VDav_5F00_4DC8C566.png"&gt;&lt;img title="VDav" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="VDav" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0640.VDav_5F00_thumb_5F00_2C691FCA.png" width="600" height="200" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you may know, you can easily develop native applications for &lt;strong&gt;Windows 8&lt;/strong&gt; using &lt;strong&gt;JavaScript&lt;/strong&gt; and &lt;strong&gt;WinJS&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Among a lot of other things, &lt;strong&gt;WinJS&lt;/strong&gt; allows you to create custom control in order to factorize your UI.&lt;/p&gt;  &lt;p&gt;Today, I would like to show you how to create this kind of control and to do so, please let me introduce you with the final version of the control:&lt;/p&gt;  &lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;  &lt;!--more--&gt;  &lt;p&gt;As you can see, this is a 3D carousel that can be used to display a long list of items alongside a great (if you like it&lt;img class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2766.wlEmoticon_2D00_smile_5F00_18B3BDC6.png" /&gt;) mirror.&lt;/p&gt;  &lt;p&gt;The sample Visual Studio 2012 project can be &lt;a href="http://www.catuhe.com/msdn/darkstone.zip"&gt;downloaded here&lt;/a&gt;.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;(If you want to know how to achieve the same goal but with C# and XAML, you can read this article written by my colleague Sébastien Pertus: &lt;a title="http://blogs.msdn.com/b/mim/archive/2013/03/19/create-a-custom-user-control-using-xaml-and-c-for-windows-8.aspx" href="http://blogs.msdn.com/b/mim/archive/2013/03/19/create-a-custom-user-control-using-xaml-and-c-for-windows-8.aspx"&gt;http://blogs.msdn.com/b/mim/archive/2013/03/19/create-a-custom-user-control-using-xaml-and-c-for-windows-8.aspx&lt;/a&gt;)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So you may now wonder how you can develop such a beautiful (!!) control. The response will be decomposed on 6 parts:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="#chap1"&gt;How to set up the layout?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap2"&gt;Declaring and instancing the control&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap3"&gt;Using templates&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap4"&gt;Using data binding&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap5"&gt;Integrating user inputs and animations&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap6"&gt;Adding events&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#chap7"&gt;Optimizations&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; &lt;a id="chap1"&gt;&lt;/a&gt;  &lt;h1&gt;How to set up the layout?&lt;/h1&gt;  &lt;p&gt;The control itself is built using a grid (&lt;a href="http://www.w3.org/TR/css3-grid/"&gt;CSS3 Grid&lt;/a&gt;) defined as the “&lt;em&gt;&lt;strong&gt;carousel-viewport&lt;/strong&gt;&lt;/em&gt;”. Inside the viewport there are two items: one called the “&lt;em&gt;&lt;strong&gt;carousel-container&lt;/strong&gt;&lt;/em&gt;” to handle all items and one called “&lt;em&gt;&lt;strong&gt;carousel-mirror&lt;/strong&gt;&lt;/em&gt;” for the mirror (obviously).&lt;/p&gt;  &lt;p&gt;Every item is built inside a “&lt;em&gt;&lt;strong&gt;carousel-item-container&lt;/strong&gt;&lt;/em&gt;” and contains two parts: a “&lt;em&gt;&lt;strong&gt;carousel-item&lt;/strong&gt;&lt;/em&gt;” for the standard part and a “&lt;em&gt;&lt;strong&gt;carousel-mirror-item&lt;/strong&gt;&lt;/em&gt;” for the mirror part.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5808.clip_5F00_image002_5F00_515E67D3.jpg"&gt;&lt;img title="clip_image002" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/6560.clip_5F00_image002_5F00_thumb_5F00_76E7E534.jpg" width="609" height="381" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can then use the magic of &lt;strong&gt;CSS&lt;/strong&gt; in order to completely style every part of the control:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-item &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{    
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;transition&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;transform 0.1s ease&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}

&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-item:hover &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;transform&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;scale(0.95)&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;For instance, with these rules, I added a cool hover effect to my items. &lt;strong&gt;Simple&lt;/strong&gt;, isn’t it? &lt;/p&gt;
&lt;a id="chap2"&gt;&lt;/a&gt;

&lt;h1&gt;Declaring and instancing the control&lt;/h1&gt;

&lt;p&gt;To declare a custom control, you just have to declare a &lt;strong&gt;WinJS&lt;/strong&gt; class:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
    &lt;span style="background: white; color: green;"&gt;// Constructor&lt;br /&gt;    &lt;/span&gt;},
    {&lt;span style="background: white; color: green;"&gt;// Instance members
    &lt;/span&gt;}, 
    {&lt;span style="background: white; color: green;"&gt;// Static members
    &lt;/span&gt;});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The first argument of the &lt;i&gt;WinJS.Class.define&lt;/i&gt; function is the constructor of you control (used to instantiate your class), the second one is the list of instance members and the last one is the list of static members.&lt;/p&gt;

&lt;p&gt;Inside the constructor, you have to define the root &lt;strong&gt;DOM&lt;/strong&gt; elements you want to use. The instance members can be properties or public functions you want to make available.&lt;/p&gt;

&lt;p&gt;For our control, the constructor will produce the layout with the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element = element || document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.winControl = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = -1;

        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Root element
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-viewport&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Items element
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.appendChild(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspectiveOrigin = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;50% 50%&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.backgroundColor = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;Black&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The constructor is also responsible for initialization options:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;i&gt;maxVisibleItems&lt;/i&gt;: Count of items visible on each side of the current item&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;depth&lt;/i&gt;: Depth of each item relatively to previous&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;animationSpeed &lt;/i&gt;: Speed of the animation when you change the current item&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;mirrorEnabled&lt;/i&gt;: Define if the mirror is visible&lt;/li&gt;

  &lt;li&gt;&lt;i&gt;perspective&lt;/i&gt;: Value indicating the amount of perspective&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These options are defined by the user during the &lt;strong&gt;instantiation&lt;/strong&gt; of the control:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;carousel&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;DarkStone.Controls.Carousel&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-options&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;{mirrorEnabled: true}&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The instance of your class can be retrieved using the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#carousel&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).winControl;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Every exposed properties can also be manipulated by the client. Here is for instance, how a slider can control the &lt;strong&gt;perspective&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#perspective&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).onchange = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    carousel.perspective = element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#perspective&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).value;
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And the result:&lt;/p&gt;

&lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-perspective.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-perspective.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;

&lt;p&gt;In addition to the previous properties, our control also exposes some other useful members (always defined with the &lt;em&gt;WinJS.Class.define&lt;/em&gt; function):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Code hidden for readability
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;},
{
    _doBinding: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Code hidden for readability
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;},
    refreshLayout: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Code hidden for readability
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;},
    element: {
        get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element; }
    },
    itemRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Main item template
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender = value;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
        }
    },
    mirrorRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror template
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender = value;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
        }
    },
    itemsSource: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Data source
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(source) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = source;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
        }
    },
    selectedIndex: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selected index
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex; },
        set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index &amp;lt; 0 || index &amp;gt;= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length || index == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex)
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = index;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        }
    },
&lt;span style="background: white; color: green;"&gt;    // more code…       &lt;/span&gt;&lt;br /&gt; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span style="background: white; color: black;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;a id="chap3"&gt;&lt;/a&gt;

&lt;h1&gt;Using templates&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;WinJS&lt;/strong&gt; also provides a way to generate item content based on templates. For our control, I decided to use two templates: one for the item and one for the mirror.&lt;/p&gt;

&lt;p&gt;The user can define his templates like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateDiv&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;img &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-bind&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;src: imageUrl&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateImg&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;mirrorTemplate&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;mirrorContainer&amp;quot;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;img &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-bind&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;src: imageUrl&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateImg&amp;quot; /&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;class&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;opacityMask&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The templates are retrieved from the web page:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender.winControl;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;mirrorTemplate= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender.winControl;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And used to create the &lt;strong&gt;DOM&lt;/strong&gt; content:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;template.render(data, item);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;These templates are used by a function called &lt;i&gt;createItem&lt;/i&gt; which takes a data from the data source and generate &lt;strong&gt;DOM&lt;/strong&gt; objects using templates:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Create item
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;createItem = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(data) {
    &lt;span style="background: white; color: green;"&gt;// Creating DOM element and setting correct position
    &lt;/span&gt;&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    root.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
    root.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    root.style.opacity = 0;
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    WinJS.Utilities.addClass(root, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
&lt;br /&gt;    that._itemsRoot.appendChild(root);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    root.appendChild(item);

    WinJS.Utilities.addClass(item, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Template
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template.render(data, item);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(mirrorTemplate) {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Clone for mirror
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;clone = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        mirrorTemplate.render(data, clone);
        WinJS.Utilities.addClass(clone, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        root.appendChild(clone);
        clone.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;translateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ item.clientHeight + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px) rotateX(180deg)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
    
    that._itemsRoot.removeChild(root);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root;
};&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap4"&gt;&lt;/a&gt;

&lt;p&gt;This function generates the correct class for each part of the item. This will allow you to &lt;strong&gt;skin&lt;/strong&gt; them easily. For instance, using the following templates:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;templateDiv&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;id&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;mirrorTemplate&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;data-win-control&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;=&amp;quot;WinJS.Binding.Template&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;div&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And the following &lt;strong&gt;CSS&lt;/strong&gt; rules:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-item &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{    
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;background-color&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;red&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}

&lt;/span&gt;&lt;span style="background: white; color: maroon;"&gt;.carousel-mirror-item &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;600px&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    &lt;/span&gt;&lt;span style="background: white; color: red;"&gt;background-color&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;blue&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You will obtain the following result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4341.image_5F00_356D32DB.png"&gt;&lt;img title="image" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1602.image_5F00_thumb_5F00_7024B5E4.png" width="644" height="350" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;Using data binding&lt;/h1&gt;

&lt;p&gt;The user can define data using a property called &lt;i&gt;itemsSource&lt;/i&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;itemsSource: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Data source
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(source) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = source;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
    }
},&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can use a simple array or a&lt;i&gt; WinJS.Binding.List&lt;/i&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#carousel&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).winControl;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;list = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;WinJS.Binding.List();

list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic01.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic02.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic03.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic04.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic05.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});
list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic06.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});

carousel.itemsSource = list;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Once the &lt;i&gt;itemsSource&lt;/i&gt; is set, the control just have to browse it and call &lt;i&gt;createItem&lt;/i&gt; for each element.&lt;/p&gt;

&lt;p&gt;If you use a &lt;i&gt;WinJS.Binding.List&lt;/i&gt;, the control can also handle two events to &lt;strong&gt;dynamically&lt;/strong&gt; support insertion and deletion of items:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Events
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(usingBindingList) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;itemremoved&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item removed
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;previous = that._items.splice(evt.detail.index, 1)[0];

        that._itemsRoot.removeChild(previous);

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.detail.index &amp;lt; that.selectedIndex) {
            that.selectedIndex--;
        } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - evt.detail.index) &amp;lt;= that.maxVisibleItems) {
            that.refreshLayout();
        }
    });
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;iteminserted&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item inserted
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = evt.detail.index;
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;newOne = createItem(that._source.getAt(current));

        that._items.splice(evt.detail.index, 0, newOne);

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - current) &amp;lt;= that.maxVisibleItems) {
            that.refreshLayout();
        }
    });
}&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap5"&gt;&lt;/a&gt;

&lt;p&gt;Using this events, if the user executes this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#button1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).onclick = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    list.splice(0, 1); &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Removing first item
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;};

element.querySelector(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;#button2&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;).onclick = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
    list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic01.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;});  &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Adding new item
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;list.push({ imageUrl: &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/assets/pic02.jpg&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}); &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Adding new item
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The list will behave like this:&lt;/p&gt;

&lt;p align="center"&gt;&lt;video controls="controls" autoplay="autoplay" loop="loop" width="600"&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-events.mp4"&gt;&lt;/source&gt;&lt;source src="http://www.catuhe.com/msdn/darkstone-events.webm"&gt;&lt;/source&gt;&lt;/video&gt; &lt;/p&gt;

&lt;h1&gt;Integrating user inputs and animations&lt;/h1&gt;

&lt;p&gt;To respond to user inputs, you just have to handle&lt;strong&gt; pointer events&lt;/strong&gt;. The pointer events (&lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx"&gt;more about here&lt;/a&gt;) are used to unify mouse, touch and pens inside a single event model. So for our control, you just have to add the following code to handle all kind of inputs:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Pointer events
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.onmspointerdown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    initialOffset = evt.clientX;

    leftButtonDown = evt.buttons == 1;

    that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
};

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.onmspointermove = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!leftButtonDown)
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;moveThreshold = 40; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// 40px for a slide

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(evt.clientX - initialOffset) &amp;gt; moveThreshold) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.clientX &amp;lt; initialOffset) {
            that.selectedIndex++;
        } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
            that.selectedIndex--;
        }
        that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
};

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.onmspointerup = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
    leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The principle is simple: if the user moves his finger/mouse/pen over more than &lt;strong&gt;40&lt;/strong&gt; pixels, we can change the current item according to the direction of the movement.&lt;/p&gt;

&lt;p&gt;To create a good looking control, you must ensure that every update of the layout is animated (fast and fluid!). To do so, you may have noticed that every “&lt;em&gt;carousel-item-container&lt;/em&gt;” has a &lt;strong&gt;CSS&lt;/strong&gt; style to define transitions:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;root.style.transition = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;transform &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s ease-in-out, opacity &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s linear&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This transition defines that every change on the &lt;em&gt;transform&lt;/em&gt; and &lt;em&gt;opacity&lt;/em&gt; properties is not immediate but animated from its original value to the final value during a specific duration.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you want to learn more about &lt;b&gt;CSS3 Transitions&lt;/b&gt;, you can go just &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/css3-transitions.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To take advantage of this &lt;strong&gt;great&lt;/strong&gt; feature, the code just have to change the transformation and the opacity of each item.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The transformation itself (&lt;a href="http://www.w3.org/TR/css3-3d-transforms/"&gt;CSS 3D Transforms&lt;/a&gt;) allows elements styled with &lt;strong&gt;CSS&lt;/strong&gt; to be transformed in two-dimensional or three-dimensional space.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The transform matrix is built using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;depth = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rotation = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : ((current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -45 : 45);
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;offset = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : ((current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth : &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth);

&lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Transform
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;rotateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ rotation + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;deg) translate3d(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ &lt;br /&gt;                        (((current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) * &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth) + offset) + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px, 0px, &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ depth + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;To summarize, the items are transformed according to the following schema:&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/4442.clip_5F00_image004_5F00_4BCFAB95.jpg"&gt;&lt;img title="clip_image004" style="display: inline; background-image: none;" border="0" alt="clip_image004" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5126.clip_5F00_image004_5F00_thumb_5F00_1F4E797E.jpg" width="609" height="387" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem you can face when dealing with &lt;strong&gt;CSS 3D Transforms&lt;/strong&gt; is about &lt;em&gt;zIndex&lt;/em&gt;. Indeed, when you move objects using matrices, something objects may overlap in a wrong order.&lt;/p&gt;

&lt;p&gt;For resolving this issue, you just have to correctly organize the &lt;em&gt;zIndex&lt;/em&gt; value of your items:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Z-Index
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;total = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length;
item.style.zIndex = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? total + 1 : total - Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Using this code, you can ensure that items are rendered in the correct order (depending on their distance to the selected item).&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;opacity&lt;/em&gt; is computed using this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Opacity
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;currentOpacity;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) {
    currentOpacity = 1;
    
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;} &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    currentOpacity = 1.0 - (Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap6"&gt;&lt;/a&gt;

&lt;p&gt;Every item has an &lt;em&gt;opacity&lt;/em&gt; proportional to its distance from the current item:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8015.image_5F00_76CF9769.png"&gt;&lt;img title="image" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/7776.image_5F00_thumb_5F00_30723154.png" width="450" height="294" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;a id="chap6"&gt;&lt;/a&gt;

&lt;h1&gt;Adding events&lt;/h1&gt;

&lt;p&gt;Obviously, a good control must raise events. For instance, if an user select an item, it would be nice to raise a “&lt;em&gt;selectedindexchanged&lt;/em&gt;”.&lt;/p&gt;

&lt;p&gt;For our control, first of all you have to “dispatch” the event with the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;selectedIndex: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selected index
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex; },
    set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index &amp;lt; 0 || index &amp;gt;= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length || index == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex)
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = index;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();

        &lt;/span&gt;&lt;strong&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.dispatchEvent(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;/strong&gt;&lt;span style="background: white; color: black;"&gt;&lt;strong&gt;, {
            selectedIndex: index
        });&lt;/strong&gt;
    }
},&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;When the user changes the &lt;em&gt;selectedIndex&lt;/em&gt;, we just have to raise the event with &lt;em&gt;dispatchEvent &lt;/em&gt;function of the control.&lt;/p&gt;

&lt;p&gt;But the control will not natively provide this function. To add it, you just have to call a small WinJS function:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;WinJS.Class.mix(DarkStone.Controls.Carousel,
    WinJS.Utilities.createEventProperties(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;),
    WinJS.UI.DOMEventMixin);&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;With only these lines, you can add event listener on your control like any other control:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;carousel.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {

});&lt;/span&gt;&lt;/pre&gt;
&lt;a id="chap7"&gt;&lt;/a&gt;

&lt;h1&gt;Optimizations&lt;/h1&gt;

&lt;p&gt;Finally, just to be sure our control works well on very low end hardware, we must ensure that only visible items are effectively handled by the &lt;strong&gt;DOM&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In order to achieve this goal, we just have to remove items from the &lt;strong&gt;DOM&lt;/strong&gt; when their opacity is inferior or equal to 0. Obviously you must re-inject them when they become visible again:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: green;"&gt;// Opacity
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;currentOpacity;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) {
    currentOpacity = 1;
    
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!isPresentInsideDOM) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    }
} &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
    currentOpacity = 1.0 - (Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Virtualization
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;lt;= 0 &amp;amp;&amp;amp; isPresentInsideDOM) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.removeChild(item);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;gt; 0 &amp;amp;&amp;amp; !isPresentInsideDOM) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    }
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Using this code, we are now ready to handle &lt;strong&gt;thousands&lt;/strong&gt; of items even on a low end devices.&lt;/p&gt;

&lt;p&gt;The control is now complete, feel free to use it in &lt;a href="http://www.catuhe.com/msdn/darkstone.zip"&gt;your own app&lt;/a&gt; &lt;img class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/1588.wlEmoticon_2D00_winkingsmile_5F00_0067DFD3.png" /&gt;&lt;/p&gt;

&lt;h1&gt;Going further&lt;/h1&gt;

&lt;p&gt;If you want to read more about some subjects I addressed in this article, here are some links you may find useful:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/css3-transitions.aspx"&gt;CSS3 Transitions&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx"&gt;Pointer events&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.w3.org/TR/css3-3d-transforms/"&gt;CSS 3D Transform&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.w3.org/TR/css3-grid/"&gt;CSS3 Grid&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/20/how-to-cook-a-windows-8-application-with-html5-javascrip-css3-rtm-version.aspx"&gt;How to cook a complete Windows 8 app using HTML5/JavaScript and CSS3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;Complete code&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;complete&lt;/strong&gt; code can be downloaded &lt;a href="http://www.catuhe.com/msdn/darkstone.zip"&gt;here&lt;/a&gt; or you can copy/paste from here:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;carousel = WinJS.Class.define(
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(element, options) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element = element || document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.winControl = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = -1;

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Root element
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-viewport&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Items element
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.appendChild(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspectiveOrigin = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;50% 50%&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;stretch&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.backgroundColor = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;Black&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            WinJS.Utilities.addClass(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items = [];
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth = 0;

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Default values
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems = 15;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth = 100;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed = 0.3;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.perspective = 800;

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Options
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(options) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.depth = options.depth || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.animationSpeed = options.animationSpeed || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.perspective = options.perspective || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.perspective;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled = options.mirrorEnabled || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems = options.maxVisibleItems || &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems;
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror);
            }

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Pointer events
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;that = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;initialOffset = 0;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;MSPointerDown&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
                initialOffset = evt.clientX;

                leftButtonDown = evt.buttons == 1;

                that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;MSPointerMove&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!leftButtonDown)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;moveThreshold = 40; &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// 40px for a slide

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(evt.clientX - initialOffset) &amp;gt; moveThreshold) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.clientX &amp;lt; initialOffset) {
                        that.selectedIndex++;
                    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
                        that.selectedIndex--;
                    }
                    that._pageChanged = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                }
            }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;MSPointerUp&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
                leftButtonDown = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        },
    {
        _doBinding: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source || !&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender || (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled &amp;amp;&amp;amp; !&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender))
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;usingBindingList = (&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.getAt !== undefined&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender.winControl;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;mirrorTemplate;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorEnabled &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender)
                mirrorTemplate = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender.winControl;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;that = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;onItemClick = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selecting the current item
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;newOne = that._items.indexOf(evt.currentTarget.parentElement);
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!that._pageChanged) {
                    that.selectedIndex = newOne;
                }
            };

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Browse data source
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length; index++) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items[index];
                
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(item.parentElement) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.removeChild(item);
                }
            }
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items = [];

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create item
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;createItem = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(data, initalTransform) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                root.style.msGridRow = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridColumn = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridRowAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridColumnAlign = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msTouchAction = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;none&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(initalTransform)
                    root.style.transform = initalTransform;
                root.style.transition = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;transform &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s ease-in-out, opacity &amp;quot; &lt;br /&gt;                                                     &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ that._animationSpeed + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;s linear&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.display = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;-ms-grid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridRows = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.msGridColumns = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;1fr&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                root.style.opacity = 0;
                root.onmousemove = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) {
                    evt.preventDefault(); &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Preventing picture manipulation
                &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;};
                WinJS.Utilities.addClass(root, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item-container&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

                that._itemsRoot.appendChild(root);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                root.appendChild(item);

                item.onclick = onItemClick;
                WinJS.Utilities.addClass(item, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Template
                &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;template.render(data, item);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(mirrorTemplate) {
                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Clone for mirror
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;clone = document.createElement(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                    mirrorTemplate.render(data, clone);
                    WinJS.Utilities.addClass(clone, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;carousel-mirror-item&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
                    root.appendChild(clone);
                    clone.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;translateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ item.clientHeight + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px) rotateX(180deg)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                }
                
                that._itemsRoot.removeChild(root);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;root;
            };

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Browse data source
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.length; index++) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;data = usingBindingList ? &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.getAt(index) : &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source[index];

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.push(createItem(data));
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = 0;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Events
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(usingBindingList) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;itemremoved&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item removed
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;previous = that._items.splice(evt.detail.index, 1)[0];

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(previous.parentElement) {
                        that._itemsRoot.removeChild(previous);
                    }

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt.detail.index &amp;lt; that.selectedIndex) {
                        that.selectedIndex--;
                    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - evt.detail.index) &amp;lt;= that.maxVisibleItems) {
                        that.refreshLayout();
                    }
                });
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source.addEventListener(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;iteminserted&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(evt) { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// On item inserted
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = evt.detail.index;
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;newOne = createItem(that._source.getAt(current));

                    that._items.splice(evt.detail.index, 0, newOne);

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(Math.abs(that.selectedIndex - current) &amp;lt;= that.maxVisibleItems) {
                        that.refreshLayout();
                    }
                });
            }

            &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirror.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;translateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.element.clientHeight / 2 + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
        },
        refreshLayout: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length == 0) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;current = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;total = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length;
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; total; index++) {

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items[current];
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;isPresentInsideDOM = (item.parentElement !== &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;null&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Opacity
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;currentOpacity;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) {
                    currentOpacity = 1;
                    
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!isPresentInsideDOM) {
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
                        isPresentInsideDOM = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    }
                } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
                    currentOpacity = 1.0 - (Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems);

                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Virtualization
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;lt;= 0 &amp;amp;&amp;amp; isPresentInsideDOM) {
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.removeChild(item);
                        isPresentInsideDOM = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    } &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;else if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(currentOpacity &amp;gt; 0 &amp;amp;&amp;amp; !isPresentInsideDOM) {
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.appendChild(item);
                        isPresentInsideDOM = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                    }
                }

                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Setting opacity
                &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.opacity = currentOpacity;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(isPresentInsideDOM) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth)
                        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth = item.clientWidth;

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;depth = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth;
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rotation = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : ((current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -45 : 45);
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;offset = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? 0 : (&lt;br /&gt;                                             (current &amp;lt; &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? -&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth : &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth);

                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Transform
                    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.transform = &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;rotateY(&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ rotation + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;deg) translate3d(&amp;quot; &lt;br /&gt;                       &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ (((current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) * &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._baseWidth) + offset) + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px, 0px, &amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ depth + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px)&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Z-Index
                    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;item.style.zIndex = (current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex) ? total + 1 : total&lt;br /&gt;                       - Math.abs(current - &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex);
                }

                current++;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(current == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length)
                    current = 0;
            }
        },
        element: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._element; }
        },
        itemRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Main item template
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemRender = value;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
            }
        },
        mirrorRender: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Mirror template
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._mirrorRender = value;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
            }
        },
        itemsSource: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Data source
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(source) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._source = source;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._doBinding();
            }
        },
        selectedIndex: { &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Selected index
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex; },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(index &amp;lt; 0 || index &amp;gt;= &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._items.length || index == &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.selectedIndex)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._selectedIndex = index;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.refreshLayout();

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.dispatchEvent(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, {
                    selectedIndex: index
                });
            }
        },
        animationSpeed: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed; },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._animationSpeed = value;
            }
        },
        depth: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() { &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth; },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth === value)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._depth = value;

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._refreshLayout();
            }
        },
        perspective: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;parseInt(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspective.replace(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;));
            },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._itemsRoot.style.perspective = value + &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;px&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
            }
        },
        maxVisibleItems: {
            get: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;() {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems;
            },
            set: &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(value) {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems === value) {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                }

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._maxVisibleItems = value;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;this&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;._refreshLayout();
            }
        }
    });

    WinJS.Namespace.define(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;DarkStone.Controls&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, {
        Carousel: carousel
    });
    
    WinJS.Class.mix(DarkStone.Controls.Carousel,
        WinJS.Utilities.createEventProperties(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;selectedindexchanged&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;),
        WinJS.UI.DOMEventMixin);
})();&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10403465" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML5/">HTML5</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/HTML+5/">HTML 5</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Javascript/">Javascript</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/CSS3/">CSS3</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Windows+8/">Windows 8</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/">WinRT</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Touch/">Touch</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/User+control/">User control</category></item><item><title>TechDays 2013 - Vidéos de la plénière développeurs et des sessions Coding4Fun et Geek is in da House</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/08/vid-233-os-de-la-pl-233-ni-232-re-d-233-veloppeurs-et-des-sessions-coding4fun-et-geek-is-in-da-house.aspx</link><pubDate>Fri, 08 Mar 2013 07:23:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10400573</guid><dc:creator>David Catuhe</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10400573</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10400573</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/08/vid-233-os-de-la-pl-233-ni-232-re-d-233-veloppeurs-et-des-sessions-coding4fun-et-geek-is-in-da-house.aspx#comments</comments><description>&lt;p&gt;Ben voila, tout est dans le titre &lt;img class="wlEmoticon wlEmoticon-smile" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5383.wlEmoticon_2D00_smile_5F00_73E0AE4F.png" /&gt;&lt;/p&gt;  &lt;h1&gt;Développeurs c’est le chef&lt;/h1&gt; &lt;iframe height="315" src="http://www.youtube.com/embed/FnBYFCNfIPc" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;   &lt;h1&gt;Coding4Fun 2013&lt;/h1&gt; &lt;iframe height="315" src="http://www.youtube.com/embed/wTtnhal35Rc" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;   &lt;h1&gt;Geek is in the house&lt;/h1&gt; &lt;iframe height="315" src="http://www.youtube.com/embed/wVzu1HsJNiw" frameborder="0" width="560" allowfullscreen="allowfullscreen"&gt;&lt;/iframe&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10400573" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/TechDays/">TechDays</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Coding4Fun/">Coding4Fun</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Geek+is+in+the+house/">Geek is in the house</category></item><item><title>Developing a WinRT component to create a video file using Media Foundation</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/06/developing-a-winrt-component-to-create-a-video-file-using-media-foundation.aspx</link><pubDate>Wed, 06 Mar 2013 10:00:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10399839</guid><dc:creator>David Catuhe</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10399839</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10399839</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/03/06/developing-a-winrt-component-to-create-a-video-file-using-media-foundation.aspx#comments</comments><description>&lt;p&gt;After creating a GIF file using my previous &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/how-to-create-an-animated-gif-with-winrt.aspx"&gt;article&lt;/a&gt;, I propose you to use the power of &lt;strong&gt;WinRT&lt;/strong&gt; to create a component in order to produce video file from your drawings (using for instance a canvas with &lt;strong&gt;Javascript&lt;/strong&gt;).&lt;/p&gt;  &lt;p&gt;To do so, we will use &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx"&gt;Media Foundation&lt;/a&gt; COM components. Media Foundation is the next generation multimedia platform for Windows that enables developers, consumers, and content providers to embrace the new wave of premium content with enhanced robustness, unparalleled quality, and seamless interoperability.&lt;/p&gt;  &lt;p&gt;And as I said before, Media Foundation is based on COM components. But thanks to C++ projects for Windows Store, we can create a &lt;strong&gt;WinRT&lt;/strong&gt; component on top of Media Foundation in order to use it from our &lt;strong&gt;Javascript&lt;/strong&gt; or &lt;strong&gt;.NET&lt;/strong&gt; projects.&lt;/p&gt;  &lt;p&gt;&lt;img title="DavBlog" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="DavBlog" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/2543.DavBlog_5F00_0FD61986.jpg" width="600" height="338" /&gt;&lt;/p&gt;  &lt;!--more--&gt;  &lt;p&gt;This &lt;strong&gt;WinRT&lt;/strong&gt; component will be called VideoGenerator.&lt;/p&gt;  &lt;h1&gt;The VideoGenerator component&lt;/h1&gt;  &lt;p&gt;The &lt;em&gt;VideoGenerator&lt;/em&gt; class will have a main method called &lt;em&gt;AppendNewFrame&lt;/em&gt;. This method is used to add a new frame to the video.&lt;/p&gt;  &lt;p&gt;The class requires the following information to work:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Frame’s width&lt;/li&gt;    &lt;li&gt;Frame’s height&lt;/li&gt;    &lt;li&gt;Delay between frames (in milliseconds)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The class itself can be like the following:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;public ref class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sealed
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
    VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height, Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ stream,&lt;br /&gt;                   &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delay);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;virtual &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;~VideoGenerator();

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^videoFrameBuffer);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Finalize();
};&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Obviously, this class also requires private data to work:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoWidth;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;fps;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bitRate;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameSize;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encodingFormat;
&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;inputFormat;
&lt;/span&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;videoWidth&lt;/em&gt; is the width of a frame&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;videoHeight&lt;/em&gt; is the height of a frame&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;fps&lt;/em&gt; is the number of frames per second&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;bitRate&lt;/em&gt; is obviously the bits rate&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;frameSize&lt;/em&gt; is equal to &lt;em&gt;videoWidth&lt;/em&gt; * &lt;em&gt;videoHeight&lt;/em&gt;&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;encodingFormat&lt;/em&gt; defines the encoder to use (WMV for us)&lt;/li&gt;

  &lt;li&gt;&lt;em&gt;inputFormat&lt;/em&gt; defines the format of the pixels sent to this class (RGB32)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;Initialization&lt;/h1&gt;

&lt;p&gt;Starting with this information, here is the constructor:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;br /&gt;                               Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    videoWidth = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    videoHeight = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    fps = 25;
    bitRate = 400000;
    frameSize = videoWidth * videoHeight;
    encodingFormat = MFVideoFormat_WMV3;
    inputFormat = MFVideoFormat_RGB32;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = CoInitializeEx(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;COINIT_APARTMENTTHREADED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFStartup(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;MF_VERSION&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
        {
            hr = InitializeSinkWriter(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
            {
                initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                rtStart = 0;
                rtDuration = (10000000 * &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;) / 1000;
            }
        }
    }
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This method needs to initialize COM engine (&lt;em&gt;CoInitializeEx&lt;/em&gt;) and also needs to initialize Media Foundation (&lt;em&gt;MFStartup&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;To compile you will need the following includes:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Windows.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfapi.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfidl.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Mfreadwrite.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mferror.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;wrl\client.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;memory&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;u&gt;Please note that the bigger the &lt;em&gt;bitRate&lt;/em&gt; is the bigger the file will be.&lt;/u&gt; 

&lt;p&gt;The next step after initializing things is to create a sink writer (&lt;em&gt;IMFSinkWriter&lt;/em&gt;) which is used to control writings to the output file.&lt;/p&gt;

&lt;p&gt;The sink writer enables you to author media files by passing in uncompressed or encoded data. For example, you can use it to re-encode a video file, or to capture live video from a webcam to a file.&lt;/p&gt;

&lt;p&gt;In our case we will use it by passing uncompressed data from .NET or javascript.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::InitializeSinkWriter(Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{    
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFAttributes&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spAttr;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeOut;   
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeIn;           
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFByteStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spByteStream;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMFByteStreamOnStreamEx((&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IUnknown&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &amp;amp;spByteStream);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {        
        MFCreateAttributes(&amp;amp;spAttr, 10);
        spAttr-&amp;gt;SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        hr = MFCreateSinkWriterFromURL(L&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.wmv&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, spByteStream.Get(), spAttr.Get(), &amp;amp;sinkWriter);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the output media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeOut);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_SUBTYPE, encodingFormat);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_AVG_BITRATE, bitRate);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeOut.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;AddStream(mediaTypeOut.Get(), &amp;amp;streamIndex);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the input media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeIn);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_SUBTYPE, inputFormat);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeIn.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;SetInputMediaType(streamIndex, mediaTypeIn.Get(), &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Tell the sink writer to start accepting data.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;BeginWriting();
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Starting from a WinRT Stream, you have to call &lt;em&gt;MFCreateMFByteStreamOnStreamEx&lt;/em&gt; method to convert it to a &lt;em&gt;IMFByteStream&lt;/em&gt; object. Then using &lt;em&gt;MFCreateSinkWriterFromURL&lt;/em&gt; you can grab the sink writer.&lt;/p&gt;

&lt;p&gt;The following part of the code is dedicated to configure the input and output format of the sink writer accordingly to defined parameters (&lt;em&gt;mediaTypeOut&lt;/em&gt; and &lt;em&gt;mediaTypeIn&lt;/em&gt; objects).&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;mediaTypeOut&lt;/em&gt; is responsible for:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms702272(v=vs.85).aspx"&gt;MF_MT_MAJOR_TYPE&lt;/a&gt;: The main type of the file (Video here)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms700208(v=vs.85).aspx"&gt;MF_MT_SUBTYPE&lt;/a&gt;: The subtype (WMV here)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-nz/library/windows/desktop/ms703792"&gt;MF_MT_AVG_BITRATE&lt;/a&gt;: The bit rate or the compression rate if you will (Defines the quality of the video)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms694868(VS.85).aspx"&gt;MF_MT_INTERLACE_MODE&lt;/a&gt;: Interlace mode (Progressive for us)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms701619(VS.85).aspx"&gt;MF_MT_FRAME_SIZE&lt;/a&gt;: The size of the frame (width and height)&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms700140(v=vs.85).aspx"&gt;MF_MT_FRAME_RATE&lt;/a&gt;: Frame per second&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms704767(VS.85).aspx"&gt;MF_MT_PIXEL_ASPECT_RATIO&lt;/a&gt;: Aspect ratio&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;em&gt;mediaTypeIn&lt;/em&gt; is responsible for:&lt;/p&gt;

&lt;ul&gt;&lt;!--StartFragment--&gt;
  &lt;li&gt;MF_MT_MAJOR_TYPE: The main type of the file (Video here)&lt;/li&gt;

  &lt;li&gt;MF_MT_SUBTYPE: The subtype (RGB32 here)&lt;/li&gt;

  &lt;li&gt;MF_MT_INTERLACE_MODE: Interlace mode (Progressive for us)&lt;/li&gt;

  &lt;li&gt;MF_MT_FRAME_SIZE: The size of the frame (width and height)&lt;/li&gt;

  &lt;li&gt;MF_MT_FRAME_RATE: Frame per second&lt;/li&gt;

  &lt;li&gt;MF_MT_PIXEL_ASPECT_RATIO: Aspect ratio&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;Adding a new frame&lt;/h1&gt;

&lt;p&gt;Once we have a sink writer, you just have to append new frame by sending a byte array to the component:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;length = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Length / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sizeof&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*buffer = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Data);
    std::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;unique_ptr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt; target(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[length]);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; length; index++)
    {
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;color = buffer[index];
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;b = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x00FF0000) &amp;gt;&amp;gt; 16);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;g = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x0000FF00) &amp;gt;&amp;gt; 8);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;r = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x000000FF));

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ARM
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;row = index / videoWidth;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;targetRow = videoHeight - row - 1;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;column = index - (row * videoWidth);
        target[(targetRow * videoWidth) + column] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#else
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;target[index] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#endif
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send frame to the sink writer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = WriteFrame(target.get(), rtStart, rtDuration);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;FAILED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;throw &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Exception&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::CreateException(hr);
    }
    rtStart += rtDuration;
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Before writing data, you have to prepare it because:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Data must be provided using RGB format and in my case (HTML5 canvas), data is stored using BGR format&lt;/li&gt;

  &lt;li&gt;On ARM devices (detected thanks to the define #ARM), data is stored starting from the last line (and not the first line) so you have to revert them on the Y axis&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, when your data is ready, just call the following code to append it to the output file:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::WriteFrame(
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Time stamp.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Frame duration.
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFSample&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; sample;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; buffer;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONG &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth = 4 * videoWidth;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbBuffer = cbWidth * videoHeight;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*pData = &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a new memory buffer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMemoryBuffer(cbBuffer, &amp;amp;buffer);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Lock the buffer and copy the video frame to the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;Lock(&amp;amp;pData, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCopyImage(
            pData,                      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination buffer.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// First row in source image.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Source stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image width in bytes.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image height in pixels.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(buffer.Get())
    {
        buffer-&amp;gt;Unlock();
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the data length of the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;SetCurrentLength(cbBuffer);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a media sample and add the buffer to the sample.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateSample(&amp;amp;sample);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;AddBuffer(buffer.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the time stamp and the duration.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleTime(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleDuration(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send the sample to the Sink Writer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;WriteSample(streamIndex, sample.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}
&lt;/span&gt;&lt;/pre&gt;
The code creates a sample, fill it with your data and set time and duration before writing the sample to the sink writer. 

&lt;h1&gt;Closing and cleaning&lt;/h1&gt;

&lt;p&gt;When you are done, you just have to call the Finalize method (and for the sake of completeness, I also add the destructor here):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::~VideoGenerator()
{
    Finalize();
}

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::Finalize()
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!initiated)
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    sinkWriter-&amp;gt;Finalize();
    MFShutdown();
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Finalization is just about closing the sink writer and release Media Foundation API (&lt;em&gt;MFShutdown&lt;/em&gt;).&lt;/p&gt;

&lt;h1&gt;Using VideoGenerator&lt;/h1&gt;

&lt;p&gt;VideoGenerator is a WinRT component so you can easily use it from .NET or Javascript. For instance, using Javascript, the client code can be something like that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;picker = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage.Pickers.FileSavePicker();
picker.fileTypeChoices.insert(Flipflop.Tools.GetString(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;VideoFiles&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;), [&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.wmv&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;]);

picker.pickSaveFileAsync().then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(file) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!file) {
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
    file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(stream) {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoGenerator = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;VideoTools.VideoGenerator(800, 600, stream, 16);

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;commandsIndex = 0; commandsIndex &amp;lt; 50; commandsIndex++) {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;canvas = document.getElementById(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;canvas&amp;quot; &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;+ commandsIndex);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;context = canvas.getContext(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;data = context.getImageData(0, 0, width, height);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bytes = data.data;
            videoGenerator.appendNewFrame(bytes);
        }

        videoGenerator.finalize();
        stream.close();
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;    }&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
});&lt;/span&gt;&lt;/pre&gt;

&lt;h1&gt;Complete code&lt;/h1&gt;

&lt;p&gt;The complete VideoGenerator code can be found &lt;a href="http://www.catuhe.com/msdn/VideoTools.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Or copy/paste right here.&lt;/p&gt;

&lt;h2&gt;VideoGenerator.h&lt;/h2&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#pragma once
#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Windows.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfapi.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mfidl.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;Mfreadwrite.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;mferror.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;wrl\client.h&amp;gt;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;lt;memory&amp;gt;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Microsoft::WRL;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;VideoTools
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public ref class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sealed
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoWidth;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;fps;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bitRate;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameSize;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encodingFormat;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GUID   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;inputFormat;

        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD  &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;streamIndex;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFSinkWriter&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; sinkWriter;

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;bool   &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;initiated;

        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rtStart;
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT64 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;rtDuration;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;private&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;InitializeSinkWriter(Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ stream);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;WriteFrame(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*videoFrameBuffer, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; rtStart, &lt;br /&gt;                           &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; rtDuration);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;:
        VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height, &lt;br /&gt;                       Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ stream, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delay);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;virtual &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;~VideoGenerator();

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^videoFrameBuffer);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Finalize();
    };
}
&lt;/span&gt;&lt;/pre&gt;

&lt;h2&gt;VideoGenerator.cpp&lt;/h2&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;pch.h&amp;quot;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#include &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;VideoGenerator.h&amp;quot;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#pragma comment&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;lib&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;mfreadwrite&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#pragma comment&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;lib&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;mfplat&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#pragma comment&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;lib&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;mfuuid&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;VideoTools;

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::VideoGenerator(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;br /&gt;                               Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    videoWidth = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;width&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    videoHeight = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;height&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    fps = 25;
    bitRate = 400000;
    frameSize = videoWidth * videoHeight;
    encodingFormat = MFVideoFormat_WMV3;
    inputFormat = MFVideoFormat_RGB32;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = CoInitializeEx(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;COINIT_APARTMENTTHREADED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFStartup(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;MF_VERSION&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
        {
            hr = InitializeSinkWriter(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
            {
                initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
                rtStart = 0;
                rtDuration = (10000000 * &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;delay&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;) / 1000;
            }
        }
    }
}

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::~VideoGenerator()
{
    Finalize();
}

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::Finalize()
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!initiated)
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    initiated = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;false&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    sinkWriter-&amp;gt;Finalize();
    MFShutdown();
}

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;void &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::AppendNewFrame(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Array&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; ^&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;length = &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Length / &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;sizeof&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*buffer = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;-&amp;gt;Data);
    std::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;unique_ptr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt; target(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[length]);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;UINT32 &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;index = 0; index &amp;lt; length; index++)
    {
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;color = buffer[index];
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;b = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x00FF0000) &amp;gt;&amp;gt; 16);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;g = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x0000FF00) &amp;gt;&amp;gt; 8);
        &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;r = (&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)((color &amp;amp; 0x000000FF));

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ARM
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;row = index / videoWidth;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;targetRow = videoHeight - row - 1;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;auto &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;column = index - (row * videoWidth);
        target[(targetRow * videoWidth) + column] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#else
        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;target[index] = (r &amp;lt;&amp;lt; 16) + (g &amp;lt;&amp;lt; 8) + b;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;#endif
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;}

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send frame to the sink writer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = WriteFrame(target.get(), rtStart, rtDuration);
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;FAILED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;throw &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Platform::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;Exception&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::CreateException(hr);
    }
    rtStart += rtDuration;
}

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::InitializeSinkWriter(Windows::Storage::Streams::&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IRandomAccessStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;^ &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{    
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFAttributes&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spAttr;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeOut;   
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt;  mediaTypeIn;           
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFByteStream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; spByteStream;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMFByteStreamOnStreamEx((&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IUnknown&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;stream&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &amp;amp;spByteStream);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {        
        MFCreateAttributes(&amp;amp;spAttr, 10);
        spAttr-&amp;gt;SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;true&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);

        hr = MFCreateSinkWriterFromURL(L&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.wmv&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, spByteStream.Get(), spAttr.Get(), &amp;amp;sinkWriter);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the output media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeOut);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetGUID(MF_MT_SUBTYPE, encodingFormat);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_AVG_BITRATE, bitRate);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeOut-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeOut.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;AddStream(mediaTypeOut.Get(), &amp;amp;streamIndex);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the input media type.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateMediaType(&amp;amp;mediaTypeIn);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetGUID(MF_MT_SUBTYPE, inputFormat);     
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = mediaTypeIn-&amp;gt;SetUINT32(MF_MT_INTERLACE_MODE, &lt;/span&gt;&lt;span style="background: white; color: rgb(47, 79, 79);"&gt;MFVideoInterlace_Progressive&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeSize(mediaTypeIn.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_FRAME_RATE, fps, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1);   
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;SetInputMediaType(streamIndex, mediaTypeIn.Get(), &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);   
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Tell the sink writer to start accepting data.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;BeginWriting();
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}

&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT VideoGenerator&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;::WriteFrame(
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Time stamp.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONGLONG&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;amp; &lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Frame duration.
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFSample&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; sample;
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ComPtr&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IMFMediaBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;gt; buffer;

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;LONG &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth = 4 * videoWidth;
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;const &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;DWORD &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbBuffer = cbWidth * videoHeight;

    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*pData = &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a new memory buffer.
    &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;HRESULT &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr = MFCreateMemoryBuffer(cbBuffer, &amp;amp;buffer);

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Lock the buffer and copy the video frame to the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;Lock(&amp;amp;pData, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, &lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;NULL&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCopyImage(
            pData,                      &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination buffer.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Destination stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BYTE&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;*)&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;videoFrameBuffer&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// First row in source image.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Source stride.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;cbWidth,                    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image width in bytes.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;videoHeight                &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Image height in pixels.
            &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(buffer.Get())
    {
        buffer-&amp;gt;Unlock();
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the data length of the buffer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = buffer-&amp;gt;SetCurrentLength(cbBuffer);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Create a media sample and add the buffer to the sample.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = MFCreateSample(&amp;amp;sample);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;AddBuffer(buffer.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Set the time stamp and the duration.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleTime(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtStart&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sample-&amp;gt;SetSampleDuration(&lt;/span&gt;&lt;span style="background: white; color: gray;"&gt;rtDuration&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;);
    }

    &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// Send the sample to the Sink Writer.
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: rgb(111, 0, 138);"&gt;SUCCEEDED&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(hr))
    {
        hr = sinkWriter-&amp;gt;WriteSample(streamIndex, sample.Get());
    }

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;hr;
}
&lt;/span&gt;&lt;/pre&gt;

&lt;h1&gt;Going further&lt;/h1&gt;

&lt;p&gt;Some useful links to go further:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Media foundation doc: &lt;a title="http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx" href="http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx"&gt;http://msdn.microsoft.com/en-us/library/windows/apps/ms694197.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;About Media foundation: &lt;a title="http://msdn.microsoft.com/en-us/library/windows/apps/ms696274.aspx" href="http://msdn.microsoft.com/en-us/library/windows/apps/ms696274.aspx"&gt;http://msdn.microsoft.com/en-us/library/windows/apps/ms696274.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Creating a &lt;strong&gt;WinRT&lt;/strong&gt; component – part 1:&lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/13/creating-a-winrt-component-using-c-cx-deform-a-direct2d-effect-toolkit.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/13/creating-a-winrt-component-using-c-cx-deform-a-direct2d-effect-toolkit.aspx"&gt;http://blogs.msdn.com/b/eternalcoding/archive/2012/08/13/creating-a-winrt-component-using-c-cx-deform-a-direct2d-effect-toolkit.aspx&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Creating a &lt;strong&gt;WinRT&lt;/strong&gt; component – part 2: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/28/creating-a-winrt-component-using-c-cx-part-2-adding-a-custom-direct2d-effect-to-deform.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/08/28/creating-a-winrt-component-using-c-cx-part-2-adding-a-custom-direct2d-effect-to-deform.aspx"&gt;http://blogs.msdn.com/b/eternalcoding/archive/2012/08/28/creating-a-winrt-component-using-c-cx-part-2-adding-a-custom-direct2d-effect-to-deform.aspx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10399839" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/">WinRT</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Video/">Video</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Media+Foundation/">Media Foundation</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/WMV/">WMV</category></item><item><title>How to create an animated GIF with WinRT</title><link>http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/how-to-create-an-animated-gif-with-winrt.aspx</link><pubDate>Thu, 28 Feb 2013 15:05:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10398174</guid><dc:creator>David Catuhe</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/rsscomments.aspx?WeblogPostID=10398174</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/eternalcoding/commentapi.aspx?WeblogPostID=10398174</wfw:comment><comments>http://blogs.msdn.com/b/eternalcoding/archive/2013/02/28/how-to-create-an-animated-gif-with-winrt.aspx#comments</comments><description>&lt;h1&gt;Why using GIF files?&lt;/h1&gt;  &lt;p&gt;For one of my project (&lt;strong&gt;Flipflop&lt;/strong&gt;: &lt;a href="http://apps.microsoft.com/windows/app/flipflop/99c01512-fe4f-4d1a-872e-eb9fd6638ff4"&gt;http://apps.microsoft.com/windows/app/flipflop/99c01512-fe4f-4d1a-872e-eb9fd6638ff4&lt;/a&gt;), I needed to create an animated GIF based on a group of HTML5 canvas.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/5734.intro0_5F00_0B174B13.gif"&gt;&lt;img title="intro0" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="intro0" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/8865.intro0_5F00_thumb_5F00_14FC3C7E.gif" width="300" height="120" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;em&gt;&lt;font size="1"&gt;A GIF produced by Flipflop&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The main goal of &lt;strong&gt;Flipflop&lt;/strong&gt; is to allow users to create an animated flipbook. And to allow them to share it, I finally found that GIF files were a great deal.&lt;/p&gt;  &lt;h1&gt;Creating a GIF using WIC components&lt;/h1&gt;  &lt;p&gt;So I propose you to share the small class that I used to achieve this goal: &lt;strong&gt;GifMaker&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;To work this class requires you to specify frames size and obviously all frames:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;System;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;System.Collections.Generic;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;System.Runtime.InteropServices.WindowsRuntime;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Foundation;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Graphics.Imaging;
&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;using &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage;

&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;namespace &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Utilities
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public sealed class &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;GifMaker
    &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;readonly &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt; frames = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;List&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[]&amp;gt;();
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;private readonly uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameWidth;
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;private readonly uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;frameHeight;

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;GifMaker(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;width, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;uint &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;height)
        {
            frameWidth = width;
            frameHeight = height;
        }

        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;public void &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;AppendNewFrame([&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;ReadOnlyArray&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;]&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;byte&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;[] frame)
        {
            frames.Add(frame);
        }&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This class mainly uses &lt;em&gt;&lt;strong&gt;WIC&lt;/strong&gt;&lt;/em&gt; or actually &lt;em&gt;&lt;strong&gt;Windows.Graphics&lt;/strong&gt;&lt;/em&gt; namespace. This namespace contains a class called &lt;em&gt;&lt;strong&gt;BitmapEncoder&lt;/strong&gt;&lt;/em&gt; that will allow us to generate files using specific encoders such as GifEncoder.&lt;/p&gt;

&lt;p&gt;The point is that GIF files are composed of a list of frames. You just have to browse through them and send each of them to the encoder using &lt;em&gt;&lt;strong&gt;GoToNextFrameAsync&lt;/strong&gt;&lt;/em&gt; to register a new frame:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;public &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IAsyncInfo &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;GenerateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;StorageFile &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;AsyncInfo&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;async &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ctx =&amp;gt;
        {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;outStream = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file.OpenAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;FileAccessMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.ReadWrite);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.CreateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.GifEncoderId, outStream);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; frames.Count; i++)
            {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;pixels = frames[i];
                encoder.SetPixelData(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapPixelFormat&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Rgba8, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapAlphaMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Ignore,
                                     frameWidth, frameHeight,
                                     92.0, 92.0,
                                     pixels);
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(i &amp;lt; frames.Count - 1)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.GoToNextFrameAsync();
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.FlushAsync();
            outStream.Dispose();
        });
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Easy, isn’t it ?&lt;/p&gt;

&lt;h1&gt;Adding delay between frames&lt;/h1&gt;

&lt;p&gt;To be complete, you also have to handle the delay between frames and for this point, I must admit it took me a long time to figure out how to do that. &lt;/p&gt;

&lt;p&gt;The solution is handled by frame properties (&lt;strong&gt;&lt;em&gt;encoder.BitmapProperties&lt;/em&gt;&lt;/strong&gt;) and especially via the property named “/grctlext/Delay” (!!).&lt;/p&gt;

&lt;p&gt;To the final code is like the following:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;public &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;IAsyncInfo &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;GenerateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;StorageFile &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file, &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;delay)
{
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;AsyncInfo&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Run(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;async &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;ctx =&amp;gt;
        {
            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;outStream = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;file.OpenAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;FileAccessMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.ReadWrite);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.CreateAsync(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapEncoder&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.GifEncoderId, outStream);

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;int &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;i = 0; i &amp;lt; frames.Count; i++)
            {
                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;pixels = frames[i];
                encoder.SetPixelData(&lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapPixelFormat&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Rgba8, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapAlphaMode&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.Ignore,
                                     frameWidth, frameHeight,
                                     92.0, 92.0,
                                     pixels);

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(i == 0)
                {
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;properties = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapPropertySet
                        &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;{
                            {
                                &lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;/grctlext/Delay&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;,
                                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;BitmapTypedValue&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(delay / 10, &lt;/span&gt;&lt;span style="background: white; color: rgb(43, 145, 175);"&gt;PropertyType&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;.UInt16)
                            }
                        };

                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.BitmapProperties.SetPropertiesAsync(properties);
                }

                &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(i &amp;lt; frames.Count - 1)
                    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.GoToNextFrameAsync();
            }

            &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;await &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;encoder.FlushAsync();
            outStream.Dispose();
        });
}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;Using it from other languages&lt;/h1&gt;

&lt;p&gt;For instance if you want to use it from &lt;strong&gt;JavaScript&lt;/strong&gt;, you just have to do something like that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;picker = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Windows.Storage.Pickers.FileSavePicker();
picker.fileTypeChoices.insert(&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;Gif files&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;, [&lt;/span&gt;&lt;span style="background: white; color: rgb(163, 21, 21);"&gt;&amp;quot;.gif&amp;quot;&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;]);

picker.pickSaveFileAsync().then(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;function&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(file) {
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;if &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(!file) {
&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;return&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;;
    }
    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;gifMaker = &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;new &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;Utilities.GifMaker(800, 600);

    &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;for &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;commandsIndex = 0; commandsIndex &amp;lt; currentFlipflop.pages.length; commandsIndex++) {
        &lt;/span&gt;&lt;span style="background: white; color: green;"&gt;// This code is used to retrieve canvases bytes
        &lt;/span&gt;&lt;span style="background: white; color: blue;"&gt;var &lt;/span&gt;&lt;span style="background: white; color: black;"&gt;bytes = Flipflop.Tools.GetBytesfromFlipflop(currentFlipflop.pages[commandsIndex],
            800, 600);

        gifMaker.appendNewFrame(bytes);
    }

    gifMaker.generateAsync(file, 200).done();&lt;/span&gt;&lt;span style="background: white; color: black;"&gt;
});&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Obviously it works the same way from &lt;strong&gt;.NET&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/3175.intro2_5F00_2FC8628A.gif"&gt;&lt;img title="intro2" style="margin-right: auto; margin-left: auto; float: none; display: block;" alt="intro2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-44-73-metablogapi/0842.intro2_5F00_thumb_5F00_19924738.gif" width="300" height="100" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10398174" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Canvas/">Canvas</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/C_2300_/">C#</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/WinRT/">WinRT</category><category domain="http://blogs.msdn.com/b/eternalcoding/archive/tags/Animated+GIF/">Animated GIF</category></item></channel></rss>