<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>WriteableBitmapEx Wiki Rss Feed</title><link>http://writeablebitmapex.codeplex.com/wikipage</link><description>WriteableBitmapEx Wiki Rss Description</description><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=104</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Windows Store XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;WriteableBitmapEx was also ported to &lt;a href="http://wbexembedded.codeplex.com"&gt;Windows Embedded&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource or content&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from an any platform supported image stream&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the XAML &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = BitmapFactory.New(512, 512);
ImageControl.Source = writeableBmp;
writeableBmp.GetBitmapContext();

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Blue anti-aliased line from P1(10, 20) to P2(50, 70)&lt;/span&gt;
writeableBmp.DrawLineAa(10, 20, 50, 70, Colors.Blue);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);

&lt;span style="color:Green;"&gt;// Invalidate&lt;/span&gt;
writeableBmp.Dispose();
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.de/2012/05/one-bitmap-to-rule-them-all.html"&gt;One Bitmap to Rule Them All - WriteableBitmapEx for WinRT Metro Style&lt;/a&gt; announced version 1.0.0.0 and provides some background about the WinRT Metro Style version.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Sun, 28 Oct 2012 12:07:48 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20121028120748P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=103</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Windows Store XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;WriteableBitmapEx was also ported to &lt;a href="http://wbexembedded.codeplex.com"&gt;Windows Embedded&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows Metro Style WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource or content&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from an any platform supported image stream&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the XAML &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = BitmapFactory.New(512, 512);
ImageControl.Source = writeableBmp;
writeableBmp.GetBitmapContext();

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Blue anti-aliased line from P1(10, 20) to P2(50, 70)&lt;/span&gt;
writeableBmp.DrawLineAa(10, 20, 50, 70, Colors.Blue);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);

&lt;span style="color:Green;"&gt;// Invalidate&lt;/span&gt;
writeableBmp.Dispose();
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.de/2012/05/one-bitmap-to-rule-them-all.html"&gt;One Bitmap to Rule Them All - WriteableBitmapEx for WinRT Metro Style&lt;/a&gt; announced version 1.0.0.0 and provides some background about the WinRT Metro Style version.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Sun, 28 Oct 2012 12:06:55 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20121028120655P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=102</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Metro Style XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;WriteableBitmapEx was also ported to &lt;a href="http://wbexembedded.codeplex.com"&gt;Windows Embedded&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows Metro Style WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource or content&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from an any platform supported image stream&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = BitmapFactory.New(512, 512);
ImageControl.Source = writeableBmp;
writeableBmp.GetBitmapContext();

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Blue anti-aliased line from P1(10, 20) to P2(50, 70)&lt;/span&gt;
writeableBmp.DrawLineAa(10, 20, 50, 70, Colors.Blue);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);

&lt;span style="color:Green;"&gt;// Invalidate&lt;/span&gt;
writeableBmp.Dispose();
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.de/2012/05/one-bitmap-to-rule-them-all.html"&gt;One Bitmap to Rule Them All - WriteableBitmapEx for WinRT Metro Style&lt;/a&gt; announced version 1.0.0.0 and provides some background about the WinRT Metro Style version.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Mon, 15 Oct 2012 13:02:52 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20121015010252P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=101</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Metro Style XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows Metro Style WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource or content&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from an any platform supported image stream&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = BitmapFactory.New(512, 512);
ImageControl.Source = writeableBmp;
writeableBmp.GetBitmapContext();

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Blue anti-aliased line from P1(10, 20) to P2(50, 70)&lt;/span&gt;
writeableBmp.DrawLineAa(10, 20, 50, 70, Colors.Blue);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);

&lt;span style="color:Green;"&gt;// Invalidate&lt;/span&gt;
writeableBmp.Dispose();
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.de/2012/05/one-bitmap-to-rule-them-all.html"&gt;One Bitmap to Rule Them All - WriteableBitmapEx for WinRT Metro Style&lt;/a&gt; announced version 1.0.0.0 and provides some background about the WinRT Metro Style version.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Tue, 03 Jul 2012 07:53:06 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120703075306A</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=100</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Metro Style XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows Metro Style WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource or content&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from an any platform supported image stream&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = BitmapFactory.New(512, 512);
ImageControl.Source = writeableBmp;
writeableBmp.GetBitmapContext();

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);

&lt;span style="color:Green;"&gt;// Invalidate&lt;/span&gt;
writeableBmp.Dispose();
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.de/2012/05/one-bitmap-to-rule-them-all.html"&gt;One Bitmap to Rule Them All - WriteableBitmapEx for WinRT Metro Style&lt;/a&gt; announced version 1.0.0.0 and provides some background about the WinRT Metro Style version.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Tue, 19 Jun 2012 17:45:15 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120619054515P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=99</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Metro Style XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows Metro Style WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource or content&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from an any platform supported image stream&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.de/2012/05/one-bitmap-to-rule-them-all.html"&gt;One Bitmap to Rule Them All - WriteableBitmapEx for WinRT Metro Style&lt;/a&gt; announced version 1.0.0.0 and provides some background about the WinRT Metro Style version.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Thu, 14 Jun 2012 14:31:16 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120614023116P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=98</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Metro Style XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows Metro Style WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource or content&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from an any platform supported image stream&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Thu, 14 Jun 2012 14:28:28 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120614022828P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=97</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx"&gt;WriteableBitmap&lt;/a&gt;. The WriteableBitmap class is available for Windows Phone, WPF, WinRT Metro Style XAML and Silverlight and allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx"&gt;Pixels&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx"&gt;NuGet package&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx"&gt;Issue Tracker&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx"&gt;GDI+&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for Windows Phone Silverlight, desktop Silverlight, WPF and Windows Metro Style WinRT XAML.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx"&gt;Color structure&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA"&gt;TGA image&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG image&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html"&gt;Shapes sample&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html"&gt;Fill sample&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html"&gt;Curve sample&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;this blog post&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html"&gt;Blit sample&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024"&gt;Windows Phone Interactive Curve Sample&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex"&gt;great sample&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx"&gt;Shape&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx"&gt;Line&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html"&gt;WriteableBitmap Extension Methods&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101"&gt;Bill Reiss&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com"&gt;Nikola Mihaylov (Nokola)&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225"&gt;Dr. Andrew Burnett-Thompson&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com"&gt;Adam Kinney&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/"&gt;Colin Eberhardt&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx"&gt;Steve Hawley&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/"&gt;Liam Bateman&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/"&gt;Mattias Fagerlund&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com"&gt;Wout de Zeeuw&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info"&gt;Ren&amp;#233; Schulte&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex"&gt;Ohloh statistics&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Sun, 06 May 2012 09:25:34 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20120506092534A</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=96</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics" class="externalLink"&gt;PNG image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225" class="externalLink"&gt;Dr. Andrew Burnett-Thompson&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schulte&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Fri, 16 Dec 2011 20:58:09 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111216085809P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=95</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics" class="externalLink"&gt;PNG image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.&lt;br /&gt;&lt;a href="http://www.linkedin.com/profile/view?id=54694225" class="externalLink"&gt;Dr. Andrew Burnett-Thompson&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed the portability refactoring and WPF port.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Fri, 16 Dec 2011 20:57:34 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111216085734P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=94</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics" class="externalLink"&gt;PNG image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/discussions/274445" class="externalLink"&gt;here&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased lien drawing function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Fri, 28 Oct 2011 12:49:40 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111028124940P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=93</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;
&lt;li&gt;Separate extension method to save as a  &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics" class="externalLink"&gt;PNG image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. Download &lt;a href="http://writeablebitmapex.codeplex.com/wikipage?title=http%3a%2f%2fwriteablebitmapex.codeplex.com%2fdiscussions%2f274445&amp;referringTitle=Home"&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased lien drawing function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Fri, 28 Oct 2011 12:48:19 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111028124819P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=92</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise and any arbitrary angle&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Windows Phone specific methods
&lt;ul&gt;&lt;li&gt;Save to media library and the camera roll&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased lien drawing function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Thu, 27 Oct 2011 20:33:53 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111027083353P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=91</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased lien drawing function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Thu, 27 Oct 2011 19:24:53 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111027072453P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=90</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Download?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms including an anti-aliased algorithm&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://flattr.com/thing/1949/WriteableBitmapEx"&gt;&lt;img style="border:none;" src="http://api.flattr.com/button/button-static-50x60.png" alt="Flattr this" title="Flattr this" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased lien drawing function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Thu, 27 Oct 2011 19:19:33 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20111027071933P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=89</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://flattr.com/thing/1949/WriteableBitmapEx"&gt;&lt;img style="border:none;" src="http://api.flattr.com/button/button-static-50x60.png" alt="Flattr this" title="Flattr this" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods and provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;&lt;a href="http://www.woutware.com" class="externalLink"&gt;Wout de Zeeuw&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; optimized the DrawLine method by 15%.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Fri, 22 Apr 2011 18:15:11 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20110422061511P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=88</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://flattr.com/thing/1949/WriteableBitmapEx"&gt;&lt;img style="border:none;" src="http://api.flattr.com/button/button-static-50x60.png" alt="Flattr this" title="Flattr this" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods and provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Mon, 18 Apr 2011 21:12:21 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20110418091221P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=87</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;Available as &lt;a href="http://nuget.org/List/Packages/WriteableBitmapEx" class="externalLink"&gt;NuGet package&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://flattr.com/thing/1949/WriteableBitmapEx"&gt;&lt;img style="border:none;" src="http://api.flattr.com/button/button-static-50x60.png" alt="Flattr this" title="Flattr this" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods and provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Mon, 18 Apr 2011 21:11:49 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20110418091149P</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=86</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a very good blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://flattr.com/thing/1949/WriteableBitmapEx"&gt;&lt;img style="border:none;" src="http://api.flattr.com/button/button-static-50x60.png" alt="Flattr this" title="Flattr this" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods and provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Wed, 06 Apr 2011 08:33:49 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20110406083349A</guid></item><item><title>Updated Wiki: Home</title><link>http://writeablebitmapex.codeplex.com/wikipage?version=85</link><description>&lt;div class="wikidoc"&gt;&lt;h1&gt;Description&lt;/h1&gt;The WriteableBitmapEx library is a collection of extension methods for Silverlight&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" class="externalLink"&gt;WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. The WriteableBitmap class that was added in Silverlight 3 and is also available on Windows Phone, allows the direct manipulation of a bitmap and could be used to generate fast procedural images by drawing directly to a bitmap. The WriteableBitmap API is very minimalistic and there&amp;#39;s only the raw &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(VS.95).aspx" class="externalLink"&gt;Pixels&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; array for such operations. The WriteableBitmapEx library tries to compensate that with extensions methods that are easy to use like built in methods and offer &lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps. &lt;br /&gt;The extension methods are grouped into different CS files with a partial class. It is possible to include just a few methods by using the specific source CS files directly or all extension methods through the built library assembly.&lt;br /&gt;&lt;br /&gt;See the &lt;a href="http://writeablebitmapex.codeplex.com/WorkItem/List.aspx" class="externalLink"&gt;Issue Tracker&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for a list of features that will be added in the future.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=WriteableBitmapEx&amp;DownloadId=96071" alt="wbx_announcement.png" title="wbx_announcement.png" /&gt; &lt;br /&gt;
&lt;h1&gt;Features&lt;/h1&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms533797(v=VS.85).aspx" class="externalLink"&gt;GDI+&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; like drawing functionality for the WriteableBitmap.&lt;br /&gt;Support for desktop and Windows Phone Silverlight.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Base
&lt;ul&gt;&lt;li&gt;Support for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.color(VS.95).aspx" class="externalLink"&gt;Color structure&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; (alpha premultiplication will be performed)&lt;/li&gt;
&lt;li&gt;Also overloads for faster int32 as color (assumed to be already alpha premultiplied)&lt;/li&gt;
&lt;li&gt;SetPixel method with various overloads&lt;/li&gt;
&lt;li&gt;GetPixel method to get the pixel color at a specified x, y coordinate&lt;/li&gt;
&lt;li&gt;Fast Clear methods&lt;/li&gt;
&lt;li&gt;Fast Clone method to copy a WriteableBitmap&lt;/li&gt;
&lt;li&gt;ForEach method to apply a given function to all pixels of the bitmap&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Transformation
&lt;ul&gt;&lt;li&gt;Crop method to extract a defined region&lt;/li&gt;
&lt;li&gt;Resize method with support for bilinear interpolation and nearest neighbor&lt;/li&gt;
&lt;li&gt;Rotate in 90&amp;#176; steps clockwise&lt;/li&gt;
&lt;li&gt;Flip vertical and horizontal&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Shapes
&lt;ul&gt;&lt;li&gt;Fast line drawing algorithms&lt;/li&gt;
&lt;li&gt;Ellipse, polyline, quad, rectangle and triangle&lt;/li&gt;
&lt;li&gt;Cubic Bezi&amp;#233;r, Cardinal spline and closed curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Filled shapes
&lt;ul&gt;&lt;li&gt;Fast ellipse and rectangle fill method&lt;/li&gt;
&lt;li&gt;Polygon, triangle and quad&lt;/li&gt;
&lt;li&gt;Bezi&amp;#233;r and Cardinal spline curves&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Blitting
&lt;ul&gt;&lt;li&gt;Different blend modes including alpha, additive, subtractive, multiply, mask and none&lt;/li&gt;
&lt;li&gt;Optimized fast path for non blended blitting&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Conversion
&lt;ul&gt;&lt;li&gt;Convert a WriteableBitmap to a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap from a byte array&lt;/li&gt;
&lt;li&gt;Create a WriteableBitmap easily from the application resource&lt;/li&gt;
&lt;li&gt;Write a WriteableBitmap as a &lt;a href="http://en.wikipedia.org/wiki/Truevision_TGA" class="externalLink"&gt;TGA image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; to a stream&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;

&lt;h1&gt;Live samples&lt;/h1&gt;Samples that come with the WriteableBitmapEx source code in action:
&lt;ul&gt;&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html" class="externalLink"&gt;Shapes sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; includes various scenarios where different shapes are drawn. By default a little demo is shown called &amp;quot;Breathing Flower&amp;quot;. Basically different sized circles rotating around a center ring are generated. The sample also contains a static page showing some of the possible shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/FillSample/WriteableBitmapExFillSampleTestPage.html" class="externalLink"&gt;Fill sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; starts with a demo that animates the Cardinal spline&amp;#39;s tension of the FillCurveClosed method, plus some random animated filled ellipses. The sample also contains a static page showing some of the possible filled shapes.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/CurveSample/WriteableBitmapExCurveSampleTestPage.html" class="externalLink"&gt;Curve sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; demonstrates the Bezi&amp;#233;r and Cardinal spline methods. The sample starts with a demo animation that uses the Cardinal spline DrawCurve method to draw an artificial plant that grows procedurally. The other part of the sample is interactive and allows to draw and manipulate Bezi&amp;#233;r and Cardinal splines with the mouse. See &lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;this blog post&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; for further information.&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html" class="externalLink"&gt;Blit sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; combines WriteableBitmaps and shows a neat particle effect.&lt;/li&gt;&lt;/ul&gt;
Video of the &lt;a href="http://vimeo.com/10220024" class="externalLink"&gt;Windows Phone Interactive Curve Sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;External resources:&lt;br /&gt;Adam Kinney made a &lt;a href="http://adamkinney.wordpress.com/2010/01/09/image-blitting-in-silverlight-with-writeablebitmapex" class="externalLink"&gt;great sample&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; that uses the WriteableBitmapEx library to dynamically apply a torn weathered effect to a photo.&lt;br /&gt;Erik Klimczak from Calrity Consulting wrote a blog post about &lt;a href="http://blogs.claritycon.com/blog/2011/03/30/advanced-animation-animating-15000-visuals-in-silverlight-2/" class="externalLink"&gt;Advanced Animation: Animating 15,000 Visuals in Silverlight&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;. He uses the WriteableBitmapEx to get the best performance.&lt;br /&gt;Peter Bromberg wrote a great article called &lt;a href="http://www.eggheadcafe.com/tutorials/aspnet/d312fb6f-9610-449f-a191-26fcede58730/silverlight-4-martin-fractals-with-writeablebitmapex.aspx" class="externalLink"&gt;Silverlight 4 Martin Fractals with WriteableBitmapEx&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt;
&lt;h1&gt;Performance!&lt;/h1&gt;The WriteableBitmapEx methods are much faster than the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape(VS.95).aspx" class="externalLink"&gt;Shape&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster as the Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.line(VS.95).aspx" class="externalLink"&gt;Line&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; element. So if a lot of shapes need to be drawn and anti-aliasing or other SIlverlight Shape properties are not needed, the WriteableBitmapEx methods are the right choice.&lt;br /&gt;
&lt;h1&gt;Easy to use!&lt;/h1&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Green;"&gt;// Initialize the WriteableBitmap with size 512x512 and set it as source of an Image control&lt;/span&gt;
WriteableBitmap writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(512, 512);
ImageControl.Source = writeableBmp;

&lt;span style="color:Green;"&gt;// Load an image from the calling Assembly&amp;#39;s resources only by passing the relative path&lt;/span&gt;
writeableBmp = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; WriteableBitmap(0, 0).FromResource(&lt;span style="color:#A31515;"&gt;&amp;quot;Data/flower2.png&amp;quot;&lt;/span&gt;);

&lt;span style="color:Green;"&gt;// Clear the WriteableBitmap with white color&lt;/span&gt;
writeableBmp.Clear(Colors.White);

&lt;span style="color:Green;"&gt;// Set the pixel at P(10, 13) to black&lt;/span&gt;
writeableBmp.SetPixel(10, 13, Colors.Black);

&lt;span style="color:Green;"&gt;// Get the color of the pixel at P(30, 43)&lt;/span&gt;
Color color = writeableBmp.GetPixel(30, 43);

&lt;span style="color:Green;"&gt;// Green line from P1(1, 2) to P2(30, 40)&lt;/span&gt;
writeableBmp.DrawLine(1, 2, 30, 40, Colors.Green);

&lt;span style="color:Green;"&gt;// Line from P1(1, 2) to P2(30, 40) using the fastest draw line method with the color as integer&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pixels = writeableBmp.Pixels;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; w = writeableBmp.PixelWidth;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt; h = writeableBmp.PixelHeight;
WriteableBitmapExtensions.DrawLine(pixels, w, h, 1, 2, 30, 40, myIntColor);

&lt;span style="color:Green;"&gt;// Black triangle with the points P1(10, 5), P2(20, 40) and P3(30, 10)&lt;/span&gt;
writeableBmp.DrawTriangle(10, 5, 20, 40, 30, 10, Colors.Black);

&lt;span style="color:Green;"&gt;// Red rectangle from the point P1(2, 4) that is 10px wide and 6px high&lt;/span&gt;
writeableBmp.DrawRectangle(2, 4, 12, 10, Colors.Red);

&lt;span style="color:Green;"&gt;// Filled blue ellipse with the center point P1(2, 2) that is 8px wide and 5px high&lt;/span&gt;
writeableBmp.FillEllipseCentered(2, 2, 8, 5, Colors.Blue);

&lt;span style="color:Green;"&gt;// Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] p = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
writeableBmp.DrawPolyline(p, Colors.Green);

&lt;span style="color:Green;"&gt;// Cubic Bezi&amp;#233;r curve from P1(5, 5) to P4(20, 7) with the control points P2(10, 15) and P3(15, 0)&lt;/span&gt;
writeableBmp.DrawBezier(5, 5, 10, 15, 15, 0, 20, 7,  Colors.Purple);

&lt;span style="color:Green;"&gt;// Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
&lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] pts = &lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;int&lt;/span&gt;[] { 10, 5, 20, 40, 30, 30};
writeableBmp.DrawCurve(pts, 0.5,  Colors.Yellow);

&lt;span style="color:Green;"&gt;// A filled Cardinal spline through the points P1(10, 5), P2(20, 40) and P3(30, 30) with a tension of 0.5&lt;/span&gt;
writeableBmp.FillCurveClosed(pts, 0.5,  Colors.Green);

&lt;span style="color:Green;"&gt;// Blit a bitmap using the additive blend mode at P1(10, 10)&lt;/span&gt;
writeableBmp.Blit(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; Point(10, 10), bitmap, sourceRect, Colors.White, WriteableBitmapExtensions.BlendMode.Additive);

&lt;span style="color:Green;"&gt;// Override all pixels with a function that changes the color based on the coordinate&lt;/span&gt;
writeableBmp.ForEach((x, y, color) =&amp;gt; Color.FromArgb(color.A, (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(color.R / 2), (&lt;span style="color:Blue;"&gt;byte&lt;/span&gt;)(x * y), 100));

&lt;span style="color:Green;"&gt;// Present the WriteableBitmap!&lt;/span&gt;
writeableBmp.Invalidate();

&lt;span style="color:Green;"&gt;// Take snapshot&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; clone = writeableBmp.Clone();

&lt;span style="color:Green;"&gt;// Save to a TGA image stream (file for example)&lt;/span&gt;
writeableBmp.WriteTga(stream);

&lt;span style="color:Green;"&gt;// Crops the WriteableBitmap to a region starting at P1(5, 8) and 10px wide and 10px high&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; cropped = writeableBmp.Crop(5, 8, 10, 10);

&lt;span style="color:Green;"&gt;// Rotates a copy of the WriteableBitmap 90 degress clockwise and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; rotated = writeableBmp.Rotate(90);

&lt;span style="color:Green;"&gt;// Flips a copy of the WriteableBitmap around the horizontal axis and returns the new copy&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; flipped = writeableBmp.Flip(FlipMode.Horizontal);

&lt;span style="color:Green;"&gt;// Resizes the WriteableBitmap to 200px wide and 300px high using a bilinear interpolation method&lt;/span&gt;
&lt;span style="color:Blue;"&gt;var&lt;/span&gt; resized = writeableBmp.Resize(200, 300, WriteableBitmapExtensions.Interpolation.Bilinear);
&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Additional Information&lt;/h1&gt;The WriteableBitmapEx library has its origin in several blog posts that also describe the implemenation and usage of some aspects in detail. The blog posts might be seen as the documentation.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/07/writeablebitmap-extension-methods.html" class="externalLink"&gt;WriteableBitmap Extension Methods&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introduced the SetPixel methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/10/drawing-lines-silverlight.html" class="externalLink"&gt;Drawing Lines - Silverlight WriteableBitmap Extensions II&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the DrawLine methods.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/drawing-shapes-silverlight.html" class="externalLink"&gt;Drawing Shapes - Silverlight WriteableBitmap Extensions III&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; brought the shape functionality (ellipse, polyline, quad, rectangle, triangle).&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/11/convert-encode-and-decode-silverlight.html" class="externalLink"&gt;Convert, Encode And Decode Silverlight WriteableBitmap Data&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; came with the byte array conversion methods and hows how to encode / decode a WriteableBitmap to JPEG.&lt;br /&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101/15/silverlight-blitting-and-blending-with-silverlights-writeablebitmap/" class="externalLink"&gt;Blitting and Blending with Silverlight’s WriteableBitmap&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the Blit functions.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2009/12/writeablebitmapex-writeablebitmap.html" class="externalLink"&gt;WriteableBitmapEx - WriteableBitmap extensions now on CodePlex&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced this project.&lt;br /&gt;&lt;a href="http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx" class="externalLink"&gt;Quick and Dirty Output of WriteableBitmap as TGA Image&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/01/rounder-faster-better-writeablebitmapex.html" class="externalLink"&gt;Rounder, Faster, Better - WriteableBitmapEx 0.9.0.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.0.0 and gives some further information about the curve sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/03/let-it-ring-writeablebitmapex-for.html" class="externalLink"&gt;Let it ring - WriteableBitmapEx for Windows Phone&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; introtuced the WriteableBitmapEx version for the Windows Phone and a sample.&lt;br /&gt;&lt;a href="http://kodierer.blogspot.com/2010/06/filled-to-bursting-point.html" class="externalLink"&gt;Filled To The Bursting Point - WriteableBitmapEx 0.9.5.0&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; announced version 0.9.5.0, has some information about the new Fill methods and comes with a nice sample.&lt;br /&gt;
&lt;h1&gt;Support it&lt;/h1&gt;&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;amp;hosted_button_id=RPXX29MESX8A2"&gt;&lt;img style="border:none;" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" alt="Donate" title="Donate" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://flattr.com/thing/1949/WriteableBitmapEx"&gt;&lt;img style="border:none;" src="http://api.flattr.com/button/button-static-50x60.png" alt="Flattr this" title="Flattr this" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h1&gt;Credits&lt;/h1&gt;&lt;a href="http://blogs.silverarcade.com/silverlight-games-101" class="externalLink"&gt;Bill Reiss&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote the Blit methods.&lt;br /&gt;&lt;a href="http://nokola.com" class="externalLink"&gt;Nikola Mihaylov (Nokola)&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; made some optimizations on the DrawLine and DrawRectangle methods and provided the original TgaWrite function.&lt;br /&gt;&lt;a href="http://adamkinney.com" class="externalLink"&gt;Adam Kinney&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; added some Blending modes to the Blit method.&lt;br /&gt;&lt;a href="http://www.scottlogic.co.uk/blog/colin/" class="externalLink"&gt;Colin Eberhardt&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; contributed the ForEach method.&lt;br /&gt;&lt;a href="http://www.atalasoft.com/cs/blogs/stevehawley/default.aspx" class="externalLink"&gt;Steve Hawley&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; proposed an optimization of the Clear(Color) method.&lt;br /&gt;&lt;a href="http://www.liambateman.net/index.php/about/" class="externalLink"&gt;Liam Bateman&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the Color Keying BlendMode.&lt;br /&gt;&lt;a href="http://lotsacode.wordpress.com/about/" class="externalLink"&gt;Mattias Fagerlund&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; suggested the convolution method.&lt;br /&gt;Your name here? We are always looking for valuable contributions. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://rene-schulte.info" class="externalLink"&gt;Ren&amp;#233; Schule&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; wrote all the rest and coordinates this project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ohloh.net/p/writeablebitmapex" class="externalLink"&gt;Ohloh statistics&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>teichgraf</author><pubDate>Wed, 06 Apr 2011 08:33:21 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20110406083321A</guid></item></channel></rss>