I have been working on some graphics code lately, and have been quite irritated with
SetPixel and its performance overheads. There is an alternative though: lock the bitmap and interact directly with an array of bytes each representing R, G, or B (and sometimes A, depending on whether it's an alpha bitmap or not).
Dim fp As New FastPixel(image)
fp.SetPixel(x, y, Color.Green)
What I've learnt
Bitmap.Height during an intense operation is very slow, because
GdipGetImageHeight) is used to retrieve the value, and it isn't cached.
- Using this class introduces speeds over 20 times faster than using
SetPixel, on average.
Use the class!
Sorry about the length of this article, but there isn't much to explain. It's quite basic, and I just wanted to get it out there so people could use it :>