缓慢呈现的用户控件图形 [英] Slow rendered user control graphics

查看:57
本文介绍了缓慢呈现的用户控件图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在用户控件上使用了透明的PNG图形.

多个控件(100x100px)会使完整表单的显示速度变慢,并打扰用户.

有没有一种机制可以使其更快?例如,在第一次绘制控件时,将最终图像另存为Bitmap,然后在需要绘制时不要尝试每次绘制具有透明性的所有图形.某种程度上的缓存机制.

预先感谢您的想法.

代码很简单,您只是覆盖了OnPaint,并绘制了一些图像和文本.图像具有透明度,当程序在相对较慢的计算机上运行时,这会使UI变慢.但是我当然需要透明.

Hello, I am using a transparent PNG graphic on a user control.

Several controls (100x100px) makes a slow display of complete form and disturbs users.

Is there a mechanism to make it faster? for example when at the first drawing of control, save the final image as Bitmap, then do not try to paint all graphics having transparency everytime when painting required. Somehow caching mechanism.

Thank in advance for your ideas.

The code is simple, you are just overriding the OnPaint, and drawing some image and text. The image has transparency and this makes slower UI when the program run on a relatively slower machine. But I certainly need transparency.

protected override void OnPaint(PaintEventArgs e)
{
    g.DrawImage(this.Image, r, 0, 0, this.Image.Width, this.Image.Height, GraphicsUnit.Pixel);
    g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), r, sf);
}

推荐答案

不要对此过度考虑.

所有图形在解压缩时都将转换为位图,因为压缩后的图像无法呈现到屏幕上.您可能已将图形压缩为纹理,这意味着资源将位于视频卡内存中,并且不会影响性能(某些UI范例为true).有2D和3D框架支持视频卡在不同程度上的加速.

几个"控件-一定可以控制在100个以下-不会影响任何合理的现代机器上的性能.

如果您确实遇到了现实生活中的问题,请尝试确保未将5MP图像加载到按钮上,即,如果按钮的大小为60x60,则将图像的大小设置为60x60.

最后,如果您的确在屏幕上有超过100个唯一的UI元素,我会不知所措,建议这不是用户要抱怨的图形速度.

干杯.
Don''t over-think this.

All graphics are transformed to bitmaps when they are decompressed as compressed images can''t be rendered to the screen. You may have compressed graphics as textures, which means that the resources will be in the video card memory and will not affect performance (true of some UI paradigms). There are 2D and 3D frameworks that support video card acceleration to varying levels of degrees.

"Several" controls - under 100, for certain - won''t affect performance on any reasonably modern machine.

If you''re really running into a real-life issue here, try to make sure you''re not loading 5MP images onto buttons, i.e., if you have a button that is 60x60, make your images 60x60.

Finally, if the case that you do have more than 100 unique UI elements on a screen, I will go out on a limb and suggest that it''s not the speed of the graphics that the users are going to complain about.

Cheers.


如何渲染图像?例如,如果您要在paint事件中从文件中加载每个图像,那么很显然这将是一个问题.

也许您可以使用一些与渲染图像有关的代码来更新问题,以便我(和其他人)来看看.
How do you render the image? If you would for example load each image from file in the paint event it is very clear that this is going to be a problem.

Maybe you could update the question with some code that is relevant to rendering the images so I (and others) can have a look.


这篇关于缓慢呈现的用户控件图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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