Direct2D的/ GDI +和缓慢的Windows窗体绘图 - 什么可以做什么? [英] Direct2D / GDI+ and slow Windows forms drawing - What can be done?

查看:2074
本文介绍了Direct2D的/ GDI +和缓慢的Windows窗体绘图 - 什么可以做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哎,
我工作了很多与Visual Studio 2008,.NET C#2.0-3.5和Windows Forms和我已经注意到了,像我以前很多,那GDI +是绘制控件极其缓慢。 注意,我不处理图像(JPG,GIF等)非常多。图像只在某些地方的图标。这实际上是控件/表格/ etc中都偏慢。

Hey, I'm working a lot with Visual Studio 2008, .NET C# 2.0-3.5 and Windows Forms and I have noticed, like many before me, that GDI+ is extremely slow in drawing Controls. Note that I do not deal with images (JPG, GIF etc) very much. Images are only as icons in certain places. This is actually Controls/Forms/etc that are slow to draw.

的问题是,你可以看到正在绘制控件和它可能需要几秒钟为一个看似简单的一套的控制要绘制。也就是说,它的滞后和可怕的。

The issue is that you can see Controls being drawn and it can take several seconds for a seemingly easy set of Controls to be drawn. Ie, its lagging and horrible.

我已经测试在这里我只是把一些窗体上的标签(40-50)中,按F5运行,不得不等待他们绘制。此外,滞后,而不是一个很好的经验。

I have made tests where I just put a number of Labels (40-50) on a form, hitting F5 to run and have to wait for them to be drawn. Again, lag and not a very nice experience.

所以,再有就是WPF可能会解决这个问题,但我/我们不准备迁移到WPF。因此,我四处寻找解决方法或修复和我偶然发现的Direct2D,并在读取数据时,一些其他库。

So, then there is WPF that might address this problem, but I/we are not ready to move to WPF. So I'm looking around for workarounds or fixes and I stumbled upon Direct2D, and when reading on that some other libraries.

把林一点点困惑,因此这些问题:

1)
:首先,我要的是一个相当整洁和简单的方式,只是的东西更快,硬件加速的方式替换的GDI +。的是否有可能做到这一点,而不去那边WPF而无需重写我所有的Windows窗体的代码?

1) First of, what I want is a fairly neat and simple way to just replace GDI+ with something faster and hardware accelerated approach. Is it possible to do that without going over to WPF and without having to rewrite all my Windows Forms code?

每当我阅读的Direct2D什么我看到的通常是可怕的C ++代码块长,告诉我如何手动编写代码来进行绘图。我不希望这样。

Whenever I read anything on Direct2D I see long blocks of usually horrible C++ code, telling me on how to manually write code to for drawing. I do not want that.

2)
虽然在网络上阅读,我偶然发现SlimDX,但我想不出如何使用它(我承认,我还没有试过很多写作的)。可以说,我已经有一个GUI应用程序(Windows窗体,标准的C#代码) - 我可以以某种方式使用SlimDX(或类似的东西),只是替换GDI +没有太多的重写

2) While reading on the net, I stumbled upon SlimDX, but I cannot figure out how to use it (and I admit, I havent tried very much as of writing). Lets say I already have a GUI-application (Windows Forms, standard C# code) - can I somehow use SlimDX (or something like it) to just "replace" GDI+ without too much rewriting?

我的问题是,我找不到任何例子或者这样告诉我,如果有可能使用SlimDX,Direct2D的或其他similiar东西我已经创建的Windows窗体软件,如果它是可能的 - 如何做到这一点。

My problem is I cannot find any examples or such telling me if it is possible to use SlimDX, Direct2D or other similiar things in my already-created Windows Forms software, and if it is possible - how to do it.

希望我不是太模糊=)

== ==编辑2010-09-22

我已经在我的真正的应用程序的一些测试,并分离出缓慢的事情之一是:

I have made some tests in my real app, and isolated one of the slow things to this:

当我在用户控件中添加文本的一些标签,控件调整自己以适应文本。例如,含有GroupControl适应了一下,刚加入到标签的。文本属性文字的大小。

When I add text to some Labels in a UserControl, the Controls resize themselves to fit the text. For example, the containing GroupControl adapts a bit to the size of the text that was just added to the .Text-property of the Labels.

有大约10 Label控件。在第一时间标签被更新,并且因此尺寸​​被改变,整个过程约需500毫秒。第二次标签更新,的没有的大小的变化,它需要大约0毫秒。

There are about 10 Label controls. The first time the labels are updated, and thus sizes are changed, the whole process takes about 500 ms. The second time the labels are updated, and no size changes, it takes about 0 ms.

编辑== 2 == 2010-09-22

如发现缓慢起伏之一。然后添加一个字符串文本属性它是缓慢的,如果将被加入不同的字符串的长度的文本从在那里更新前的文本。

Found one of the slow-downs. Then adding a String to the Text-property it is slow if the text that is being added differs in string length from the text that was there before the update.

即时通讯使用的DevExpress库和LabelControls可以设置为AutoSizeMode。如果我设置为无,那么滞后将增加,在长度不同于以前的文本文本时消失。我想这个问题将是正常的标签控制一样,因为它也有一个自动调整大小=真/假设置。

Im using DevExpress libraries, and the LabelControls can be set to AutoSizeMode. If I set that to "None" then the lag will go away when adding text that differs in length from the previous text. I guess this problem will be the same for the normal Label-control as it also has a AutoSize = true/false setting.

然而,它的一个解决办法,但仍证明我的观点 - 调整大小,这是相当跛脚的时候很慢

However, its a "workaround" but still proves my point - its really slow when resizing which is pretty lame.

推荐答案

许多海报上面配好点的。我创建了一个GDI +自己一个3D CAD应用程序,并发现它足够快不够的,如果它的正确实施。使用控件,不过,马上给我的印象是一个非常尴尬的方式做事情。 A控制是一个相当大的对象,并有无数的理由来让自己在这种情况下。

Many of the posters above come with good points. I've created a 3D CAD application in GDI+ myself, and found it plenty fast enough if it's implemented correctly. Using Controls, however, immediately strikes me as a very awkward way to do things. A Control is a fairly big object and there are numerous reasons to make your own in this case.

我建议你寻找到一个的保留模式绘制系统。这很容易实现,并会涵盖在大多数情况下,你的情况。你必须自己创建图纸的逻辑,但是这只是有趣,会给你更多的灵活性:)

I'd advise you to look into a retained mode drawing system. It's easy to implement and would cover your situation in most cases. You'd have to create the drawing logic yourself, but that's just fun and would give you more flexibility :)

这篇关于Direct2D的/ GDI +和缓慢的Windows窗体绘图 - 什么可以做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆