Rendering ink and image to a bitmap using WPF

To follow-up on my previous blog post and to complete the story about rendering ink onto pictures and saving the results as a bitmap file, I want to show how this is done in WPF.

In WPF all rendering uses the pipeline - pictures, videos, ink, text, all gets rendered via WPF's 'Media Integration Layer'. As a result, it's very easy and straightforward to combine rendering these different types, both on screen and on a bitmap.

I have attached a WPF sample app that demonstrates how to collect ink on top of an image and then save the combined visual to a bitmap file. In fact, I have used this sample to create the sample picture that is included in my previous post about doing this in Winforms. Here is a screenshot of the sample app (btw, the ink color picker is borrowed from the InkColorPicker SDK sample).

The key class to accomplish our job in WPF is the RenderTargetBitmap class. Here is the relevant code snippet from the sample app:

// render InkCanvas' visual tree to the RenderTargetBitmap

RenderTargetBitmap targetBitmap =

new RenderTargetBitmap((int)inkCanvas1.ActualWidth,


96d, 96d,



// add the RenderTargetBitmap to a Bitmapencoder

BmpBitmapEncoder encoder = new BmpBitmapEncoder();


// save file to disk

FileStream fs = File.Open(fileName, FileMode.OpenOrCreate);


Unlike the Winforms API, there is no behavioral difference between Windows Vista and Windows XP.