How to increase performance over GDI's DrawImage(Unscaled)?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 05:25:53

问题


In my user control's paint handler I iterate over a collection of predefined Bitmap objects and draw them to the client area thusly:

C# version:

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 version:

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

The code works fine but starts to bog down when a dozen or so objects are added to the collection. My question is: Is there a way to speed this up? Would it be possible to use the Win32 bitblt function to replace DrawImageUnscaled? And if so how?

Thanks!

Note: Googling for useage of BitBlt has only yielded me screen cap samples so far...


回答1:


Too late, but possibly somebody still need a solution.

I've created small library GLGDI+ with similiar GDI+ syntax, which run upon OpenTK: http://code.google.com/p/glgdiplus/

I'm not sure about stability, it has some issues with DrawString (problem with TextPrint from OpenTK). But if you need performance boost for your utility (like level editor in my case) it can be solution.



来源:https://stackoverflow.com/questions/2587911/how-to-increase-performance-over-gdis-drawimageunscaled

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