Manipulating a bitmap programmatically

Bitmaps are used in one form or another mainly to display existing images. These typically are placed as a source of an Image element. When a static image is added to a project and set to the Image.Source property, a BitmapImage is created behind the scenes. This simple class provides a read-only view to the bitmap's bits.

Sometime it's desirable to manipulate a bitmap's bit values dynamically based on a runtime algorithm. WPF provides the WriteableBitmap that allows us to do just that. Let's look at how to use this capability.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create an application that displays the famous Mandelbrot set, requiring calculating colors for each pixel ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.