Performance of Image drawing GDI vs GDI+

Christian Berg
Sep 7, 2018 · 2 min read

Depending of your scenario, there are a range of functions to use to draw images on the screen. As long as you avoid drawimage. Never user that function.

Unscaled Drawing

All functions scale linear with the size of the image.

drawimageunscaled

It is a fast function but it has the problem of that the image has to be of the right size. When dealing with icons or predictive data this is your go to function.

TextureBrush

It has the exact same performance as DrawImageUnscaled but with the price of instanting the object which is expensive. Use this only if you are going to reuse the same image over and over again and need the possibility to scale the image. But really. Why not use drawimageunscaled since it is equally fast and does not require an instance of a texturebrush object if you are only going for static width and height.

Blitting

Blitting it the magic but it has some limitations which will be discussed in another chapter. Blitting is 20x faster than drawimageunscaled.

Scaled Drawing

drawimage

The simplest way to draw an image is to simply to call drawimage

e.graphics.drawimage (“TheImage”, Location);

It is easy and but horrible slow. Never user this function. It is better to scale the image to the right resolution and paint it using drawimageunscale. At least if you know which size to draw the image. Interestingly enough, this is faster for large images but compared to methods. But still. slow. Avoid this one at all cost.

TextureBrush

This is your go to function when drawing images of unknown sizes. It is 20 times faster than drawimage. 20x! However, for large images (>1000x1000) pixels it is only 2x faster.

Scaled Blitting

Blitting is your friend. It is 10x faster than Texturebrush and even with the largest images it is 25x faster than drawimage.

Smooth as butter

4K is coming and you only have 20ms

Christian Berg

Written by

Smooth as butter

4K is coming and you only have 20ms

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade