WriteableBitmapEx
The WriteableBitmapEx library is a collection of extension methods for the WriteableBitmap. The WriteableBitmap class is available for WPF. It supports the .NET Framework and .NET Core 3. WriteableBitmapEx allows the direct manipulation of a bitmap and can be used for image manipulation, to generate fast procedural images by drawing directly to a bitmap and more.
The WriteableBitmap API is very minimalistic and there's only the raw Pixels 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 GDI+ like functionality. The library extends the WriteableBitmap class with elementary and fast (2D drawing) functionality, conversion methods and functions to combine (blit) WriteableBitmaps.
The extension methods are grouped into different C# files using a partial class approach. It is possible to include just a few methods by using the specific source code files directly or the full functionality via the built binaries.
The latest binaries are available as NuGet package.
Please use the GitHub Issues functionality to add new issues which are not already reported.
News
- now supports text rendering (outline and fill)
Features
GDI+ like drawing functionality for the WriteableBitmap.
Support for WPF with .NET Framework and .NET Core 3.
- Base
- Support for the Color structure (alpha premultiplication will be performed)
- Also overloads for faster int32 as color (assumed to be already alpha premultiplied)
- SetPixel method with various overloads
- GetPixel method to get the pixel color at a specified x, y coordinate
- Fast Clear methods
- Fast Clone method to copy a WriteableBitmap
- ForEach method to apply a given function to all pixels of the bitmap
- Transformation
- Crop method to extract a defined region
- Resize method with support for bilinear interpolation and nearest neighbor
- Rotate in 90° steps clockwise and any arbitrary angle
- Flip vertical and horizontal
- Shapes
- Fast line drawing algorithms including various anti-aliased algorithm
- Variable stroke thickness, dotted and penned / stamp lines
- Ellipse, polyline, quad, rectangle and triangle
- Cubic Beziér, Cardinal spline and closed curves
- Filled shapes
- Fast ellipse and rectangle fill method
- Triangle, quad, simple and complex polygons
- Beziér and Cardinal spline curves
- Text
- Fill and draw outline of text strings. text is highly flexible, it is instance of
FormattedText thus any text and characted which is supported by wpf, can be rendered (options like FlowDirection, FontWeight and ... can be changed).
- Blitting
- Different blend modes including alpha, additive, subtractive, multiply, mask and none
- Optimized fast path for non blended blitting
- Special BlitRender to apply affine transformation with bilinear interpolation
- Filtering
- Convolution, Blur
- Brightness, contrast, gamma adjustments
- Gray/brightness, invert
- Conversion
- Convert a WriteableBitmap to a byte array
- Create a WriteableBitmap from a byte array
- Create a WriteableBitmap easily from the application resource or content
- Create a WriteableBitmap from an any platform supported image stream
- Write a WriteableBitmap as a TGA image to a stream
- Separate extension method to save as a PNG image. Download here
- Windows Phone specific methods
- Save to media library and the camera roll
Performance!
The WriteableBitmapEx methods are much faster than the XAML Shape subclasses. For example, the WriteableBitmapEx line drawing approach is more than 20-30 times faster than the Silverlight Line element. If a lot of shapes need to be drawn, the WriteableBitmapEx methods are the right choice.
Easy to use!
Additional Information
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:
Support it
Credits
- Rene Schulte started this project, maintains it and provided most of the code.
- Dr. Andrew Burnett-Thompsonand his team proposed the portability refactoring, provided the WPF port and much more beneficial functions.
- Nikola Mihaylov (Nokola) made some optimizations on the DrawLine and DrawRectangle methods, provided the original TgaWrite and the anti-aliased line drawing function.
- Bill Reiss wrote the Blit methods.
And all the other amazing contributors you can see in the Contributors tab here on GitHub.