简体   繁体   English

在.NET GDI类上使用Win32 API调用

[英]Using Win32 API calls over .NET GDI Classes

I have a winforms application developed in C#, which involves a lot of screen painting. 我有一个用C#开发的winforms应用程序,它涉及很多屏幕绘画。 The painting involves rendering of custom controls and other 2D objects. 绘画涉及自定义控件和其他2D对象的渲染。 Now the problem is, it takes up approximately 4 to 5 seconds to paint the entire screen. 现在的问题是,绘制整个屏幕大约需要4到5秒钟。 I had optimized the code to a level, where all required data is made available in the memory itself rather than reading it from the disk or network. 我已经将代码优化到一个级别,在该级别中,所有必需的数据都在内存本身中可用,而不是从磁盘或网络中读取。

To further cut down the rendering time I was planning to go for the following options 为了进一步减少渲染时间,我打算选择以下选项

  1. Call directly GDI functions exposed by Win32API, instead of using the GDI classes provided by .NET 直接调用Win32API公开的GDI函数,而不是使用.NET提供的GDI类

  2. Make use of DirectX as I heard that it is much efficient at rendering. 我听说DirectX在渲染方面非常有效,请使用它。 My application doesnt involve any kind of 3D rendering. 我的应用程序不涉及任何类型的3D渲染。

Please help me to decide which option to go for? 请帮助我决定选择哪个选项? are there any options other than this, like any high performance third party components or libraries. 除此之外,还有其他选择,例如任何高性能的第三方组件或库。

From personal experience: 根据个人经验:

  • GDI+ is only slower than GDI by a factor of < 2. It won't help much to switch from .NET (which uses GDI+) to pure GDI. GDI +仅比GDI慢2倍。从.NET(使用GDI +)切换到纯GDI并没有多大帮助。

  • Direct2D is just as slow as GDI -- at least for drawing basic shapes. Direct2D与GDI一样慢-至少对于绘制基本形状而言。 So unless you're doing something a lot more complicated, it probably won't help. 因此,除非您要做的事情复杂得多,否则可能无济于事。

Your best bet is to probably cut down on the drawing, and to double-buffer the data. 最好的选择是缩减图形,并对数据进行双重缓冲。

If it doesn't work, you would probably want to generate the bitmap in memory (using a byte[] or something, avoiding graphics APIs entirely), and to simply blit (copy) it directly to the screen. 如果它不起作用,则可能要在内存中生成位图(使用byte[]或其他方法,完全避免使用图形API),然后直接将其位图(复制)到屏幕上。 It's hard, but it almost always turns out to be the fastest. 很难,但是几乎总是最快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM