Bitmap.SetPixel (x, y, Color) is too slow

So, I'm currently creating a 1000x1000 bitmap and spend about 0.3 seconds just by calling the Bitmap.SetPixel () function.

I actually draw, probably 50% of the pixels, so it looks more like 500,000 setpixel calls. While it really looks like a lot of challenges, OTOH video games do more and click a lot more pixels (some of them are generated in the process).

Obviously, Bitmap.SetPixel is not optimized for speed, but if I need to update a bitmap 20-30 times per second to get decent animation, is this a way to slow down, so what are my options?

+4
source share
4 answers

Bob Powell has an excellent tutorial on accessing pixel maps directly in memory.

+6
source

Modern video games for blockbusters perform all the pixel settings behind the scenes in hardware; they provide hardware with a geometry buffer, and highly parallel hardware does all the math. OpenGL and DirectX are APIs for communicating with hardware.

Find gamedev.net for some tutorials.

+1
source

I can recommend FastBitmap :

FastBitmap fb = new FastBitmap(b); fb.LockImage(); ... fb.SetPixel(x, y, Color.Red); ... fb.UnlockImage(); 
+1
source

All Articles