我的部分GUI很慢 [英] Part of my GUI is slow

查看:124
本文介绍了我的部分GUI很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的GUI遇到了问题。我的GUI中有多个部分。第一个是图像(从500x500到3000x3000,每秒最多需要更新4次)第二个是主菜单第三个是带有关于图像选项的按钮。我没有立刻显示所有这些,我滚动浏览几个菜单,我只渲染那些可见的菜单。 (otpions的一个例子是图像的像素大小)我在一个800x800px大的Viewbox中显示图像。我用

 Stretch ={Binding Path = StretchMode}拉伸盒子里面的图像



我得到的图像是某种流。我每秒都会得到多个图像。



现在当我显示图像时,第一个GUI部分工作正常(无论图像大小如何),但其他部分有时会很重framedrop。我将给出一些例子:



示例1:



图像大小为500x500像素。我可以在没有framedrop的情况下工作,整个gui更新正确。



示例2:



图像是1500x1500像素大。我可以在没有Framedrop的情况下工作,整个gui更新正确。



例3:



图像是2500x2500像素大。图像更新速度很快,但GUI的其余部分帧速率从60 fps到fps,有时甚至达到1 fps。



我希望你能给我一些想法为什么GUI有这种行为。如果您需要代码,请告诉我。



我没有使用虚拟机。在Windows 7 64位和Windows 8.1 64位上出现此问题(在Windows 10上不是testet)我的硬件不同。问题出现在我的笔记本电脑上(Intel i7-4702MQ @ 2.2 Ghz,8 gb ddr ram,英特尔主板显卡)和不同规格的workpc(最高的是:Intel Xeon 3.5 Ghz,128 GB DDR4 Ram和Titan X和一个4k显示器)



我尝试过:



1。硬件已达到极限。但是Visual Studio的Taskmanager和CPU / RAM分析表明它没问题。

2.渲染GUI太多了,因为3000x3000很大而且每秒4次并不慢无论是。在加载(我从硬盘驱动器加载)3000x3000图像(相同数据类型)的测试之后,它运行得很快且没有问题。

3.同时更改GUI的太多。我只用了5次更新就试用了这个软件。仍然是同样的问题。

4.未发生Microsoft Prism事件。这不是因为它进入控制器内部并且如果有变化则提升变化。 (我有一个记录器,它写入日志文件,它比GUI真正改变更多地引发Change事件)

5.使用不同的数据类型。可能,但我尝试了几个。 (BitmapSource,BitmapImage和WriteableBitmap)

6.在另一个线程中外包一些渲染选项。仍然没有变化。

解决方案

您的应用程序运行缓慢的原因有很多。你真的需要附上一个性能分析器来正确调查事情。由于我们无法访问您的任何源代码,因此我们无法明确说明性能问题究竟是什么。如果我是你,我会首先安装 WPF Performance Suite [ ^ ]并使用工具来调查发生了什么。我不得不问一个问题 - 你加载它时是否缓存并冻结了图像?试试这样的事情

 <   Image    来源  =  test。 png   拉伸  = 填写   高度  =  2500   宽度  =  2500    PresentationOptions:Freeze   =  True >  
< Image.CacheMode >
< BitmapCache PresentationOptions:Freeze < span class =code-keyword> = True / >
< / Image.CacheMode >
< / Image >

注意: PresentationOptions 在XAML中需要此命名空间:

的xmlns:PresentationOptions = http://schemas.microsoft.com/winfx/2006/xaml/presentation/options


I ran into a problem with my GUI. My GUI has multiple parts in it. The first one is for an image (from 500x500 to 3000x3000 and it has to update up to 4 times each seconds) The second one is the main menu The third one has buttons with options regarding the image. I am not showing all of them at once, I scroll through several menus and i render only the ones who are visible. (An example for the otpions is the pixelsize of the image) I display the image inside a Viewbox which is 800x800px big. I stretch the image inside of the box with

Stretch="{Binding Path=StretchMode}"


The Image I get is some kind of stream. I get multiple Images each second.

Now when I display an image, the first GUI part works fine (regardless of the image size) but the others sometimes have a heavy framedrop. I will give some examples:

Example 1:

The image is 500x500 pixel big. I can work without a framedrop and the whole gui updates correctly.

Example 2:

The image is 1500x1500 pixel big. I can work without a Framedrop and the whole gui updates correctly.

Example 3:

The image is 2500x2500 pixel big. The Image updates fast but the rest of the GUI have framedrop from 60 fps to fps and sometimes even to 1 fps.

I hope you can give me some ideas why the GUI has this behaviour. If you need code, please tell me.

I am not using a VM. The problem occurs on Windows 7 64 bit and Windows 8.1 64 bit (not testet on Windows 10) My hardware differs. The problem appears on my laptop (Intel i7-4702MQ @2.2 Ghz, 8 gb ddr ram, intel board graphics) and on workpc's with different specs (the highest are: Intel Xeon with 3.5 Ghz, 128 GB DDR4 Ram and a Titan X and a 4k Monitor)

What I have tried:

1. Hardware is at its limit. But a look on the Taskmanager and CPU/RAM analysis with Visual Studios says it is allright.
2. It is too much to render for the GUI because 3000x3000 is big and 4 times each seconds is not slow either. After a test with loaded (I loaded them from a hdd-drive) 3000x3000 images (Same Datatype) it worked fast and without problems.
3. Too much changes of the GUI at once. I tried the Software with only 5 updates. Still the same problem.
4. Microsoft Prism event not occuring. This wasn't it either because it comes inside the Controller and is Raising the changes if there is a change. (I have a logger which writes logfiles and it is raising the Change event more than the GUI is really changing)
5. Usage of a different datatype. Possible but i tried out several. (BitmapSource, BitmapImage and WriteableBitmap)
6. Outsourcing some rendering options in another thread. Still no change.

解决方案

There are many reasons your application could be running slowly. You really need to attach a performance profiler to investigate things properly. As we don't have access to any of your source code, there is no way that we are going to be able to definitively state what the performance issue really is. If I were you, I would start off by installing the WPF Performance Suite[^] and using the tooling there to investigate what's going on. One question I have to ask though - have you cached and frozen your image when you load it? Try something like this

<Image Source="test.png" Stretch="Fill" Height="2500" Width="2500" PresentationOptions:Freeze="True">
  <Image.CacheMode>
    <BitmapCache PresentationOptions:Freeze="True"/>
  </Image.CacheMode>
</Image>

NB: PresentationOptions requires this namespace in your XAML:

xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"


这篇关于我的部分GUI很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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