在我的用户控件的绘制处理程序中,我迭代了一组预定义的 Bitmap 对象并将它们绘制到客户区:
C#版本:
private void Control_Paint(object sender, PaintEventArgs e) {
Graphics g = e.Graphics;
foreach (BitmapObj bmpObj in _bitmapObjCollection) {
g.DrawImageUnscaled(bmpObj.Bitmap, bmpObj.Location);
}
}
VB.NET 版本:
Private Sub Control_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
For Each bmpObj As BitmapObj In _bitmapObjCollection
g.DrawImageUnscaled(bmpObj.Bitmap, bmpObj.Location)
Next
End Sub
代码工作正常,但当将十几个对象添加到集合中时,代码开始陷入困境。我的问题是:有没有办法加快速度?是否可以使用Win32 bitblt函数来代替DrawImageUnscaled?如果是这样的话?
谢谢!
注意:到目前为止,通过谷歌搜索 BitBlt 的用法只得到了我的屏幕截图样本......
最佳答案
太晚了,但可能有人仍然需要解决方案。
我用类似的 GDI+ 语法创建了小型库 GLGDI+,它在 OpenTK 上运行: http://code.google.com/p/glgdiplus/
我不确定稳定性,DrawString 有一些问题(来自 OpenTK 的 TextPrint 有问题)。但是,如果您需要提高实用程序的性能(例如我的关卡编辑器),它可能是解决方案。
关于c# - 如何提高 GDI 的 DrawImage(Unscaled) 的性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2587911/