Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
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
XML
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.
Posted
Updated 4-Jan-17 23:28pm
v3
Comments
Philippe Mori 5-Jan-17 9:11am    
If the images are that big, then depending on the image format, you might not even be able to read them from disk at that rate... For example, RAW images from a digital camera are quite slow compared to JPEG files.
Evosoul04 5-Jan-17 10:25am    
I get 3000x3000 Raw images as a ushort array and need to convert them to a BitmapSource. That works. The images are updating correctly, but the rest of the GUI isn't updating correctly

1 solution

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
XML
<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:
XML
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
 
Share this answer
 
Comments
Evosoul04 5-Jan-17 5:09am    
First of all thanks for your answer.
I can't install the WPF Performance Suite because I develop under Windows 8.1, but I ran all Analysis Visual Studio offers me. (the 2013 and the 2015 Version. Timeline, CPU Analysis, GPU Analysis, Memory analysis etc.) None of them really gave me information (but I am relativly new to this tools so it is possible and likely that I overlooked some things)
To your question, yes I freeze the image each time and display it. But I freeze it in C# code. Is the xaml way faster?
Pete O'Hanlon 5-Jan-17 5:15am    
It's no faster in XAML over C# (I just tend to work heavily in XAML). Have you cached your image as well?

For performance tuning, I tend to use JetBrains rather than the inbuilt VS tooling.
Evosoul04 5-Jan-17 5:19am    
I think that caching the images is not useful for me because I get multiple images each seconds. Each one is different, so caching isn't the trick for me (or am I misinterpreting caching?)
I will look into JetBrains!
Pete O'Hanlon 5-Jan-17 5:24am    
Ah it looked from your question like it was a single image of each size. Hmmm, if you're getting multiple images coming in, you've got some serious work ahead of you I'm afraid. It sounds like you're trying to push WPF beyond the limits of its graphics rendering - saying that, you can work around this by hosting DirectX windows inside WPF windows using this project: https://github.com/Microsoft/WPFDXInterop
Evosoul04 5-Jan-17 5:27am    
I am sorry for the misunderstand. I make it clear in the question!
I will look at the linked git Project. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900