Lately I have been coding a lot using WPF and one of the main area’s I’ve been involved in is the 3D rendering, however its easy to find out that there are quite a lot of performance hits across the board when it comes to WPF.
One of the biggest hits is the way it renders, normally WPF will try to do as much as possible using Hardware Graphics Acceleration however certain functionality will cause it to fall back to software based Rasterizing; such as certain BitmapEffects. So I guess there is to limit yourself to features that are fully hardware assisted.
So once everything is using the hardware there still can be slowdowns and stutters caused elsewhere in your program, one of the big issues I’ve had lately is how WPF handles ImageBrush, when loading an image it will load the entire image which if your rendering a 10mp digital photo can cause a huge slowdown if you’re using multiple instances of different brushes. There are a few tricks to start off with, firstly by altering the RenderOptions of the ImageBrush to increase its performance. Below is a sample of code that alters the RenderOptions of the brush _PictureBrush.
However this may not be enough as the pictures are still being loaded into memory, therefore to reduce their footprint, what we want instead to do is to produce and use instead a thumbnail of the original image.
public BitmapImage CreateThumbnail(Uri Source, int PreferredWidth)
BitmapImage bi = new BitmapImage();
bi.DecodePixelWidth = PreferredWidth;
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = Source;
This code takes a Uri Source and creates a thumbnail of the PeferredWidth, thus if you use this method you can drastically reduce the memory requirements of handling images as Brushes.