如何提高 GDI 的 DrawImage(Unscaled) 的性能?

发布于 2024-08-27 12:17:54 字数 824 浏览 16 评论 0原文

在我的用户控件的绘制处理程序中,我迭代预定义位图对象的集合并将它们绘制到客户区,从而:

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 的使用仅给我提供了屏幕截图示例......

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

り繁华旳梦境 2024-09-03 12:17:54

为时已晚,但可能有人仍然需要解决方案。

我使用类似的 GDI+ 语法创建了小型库 GLGDI+,它在 OpenTK 上运行:
http://code.google.com/p/glgdiplus/

我不确定稳定性方面,DrawString 存在一些问题(OpenTK 的 TextPrint 存在问题)。但如果您需要提高实用程序的性能(例如我的情况下的关卡编辑器),它可以是解决方案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文