在我的用户控件的绘制处理程序中,我迭代一组预定义的位图对象,然后将它们绘制到客户机区域:
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的谷歌搜索到目前为止只产生了我的屏幕帽样本…