虽然现在在图像图形上想提速,公认还是使用GPU了。但是如果机器没有一个好的显卡?你只是想写一个简单的.Net程序?GDI在其平台的易用性还是有很强的市场。只是一旦你需要使用GDI多次甚至大量的绘制图像时候,当你只是想简单的但是多次的复制图片的时候,使用Graphics.DrawImage()的性能绝对会崩溃。
查了很久,Gameres几个哥们给了几个很好的建议,主要思路是直接对Bitmap位操纵,这样子还可以利用多线程(注意GDI是不能多线程调用的,至少我用TPL库就不成功)。
下面用几个具体函数说明。
第一个是从一个Source Bitmap的Rectangle sourceRect的地址的内容拷贝到 Dest Bitmap 的 Point destPos起点的地址。
//Copy the data of sourceMap in sourceRect to destMap start from destPos
//Currently the method only deals with the bitmap with format Format32bppArgb.
public bool CopyBitMapWithLockBits(Bitmap sourceMap, ref Bitmap destMap, Rectangle sourceRec