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

穿精又带淫゛_ 提交于 2019-12-31 00:57:08

问题


So currently I'm creating a 1000x1000 bitmap and it's spending about .3 seconds simply calling the Bitmap.SetPixel() function.

I'm actually only drawing probably 50% of the pixels so it's more like 500,000 call to setpixel. While that does seem like a lot of calls, OTOH video games are do alot more and push many many more pixels (some of them procedureally generated).

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


回答1:


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




回答2:


FastPixel?: http://www.codeproject.com/KB/GDI-plus/FastPixel.aspx




回答3:


Modern blockbuster video games do all the pixel setting behind the scenes in hardware; they give the hardware a buffer of geometries and the highly parallelized hardware does all the math. OpenGL and DirectX are APIs for talking to the hardware.

Search gamedev.net for some tutorials.




回答4:


I can recommend FastBitmap:

FastBitmap fb = new FastBitmap(b);
fb.LockImage();

...

fb.SetPixel(x, y, Color.Red);

...

fb.UnlockImage();


来源:https://stackoverflow.com/questions/1490000/bitmap-setpixelx-y-color-too-slow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!