Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Create Image Async (Read 2975 times)
KillaChris19
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 8
Joined: Mar 9th, 2018
Create Image Async
Mar 16th, 2018 at 12:45pm
Print Post  
Hello,
I'd like to know if there is some possibility or if it is planned to have an async version of the CreateImage function.
Perhaps with a callback to display a progress?

In some cases I have very large Diagrams and the call to CreateImage takes about 2-3 minutes. So it would be very useful if there is a possibility to do this in an async way.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Create Image Async
Reply #1 - Mar 16th, 2018 at 2:30pm
Print Post  
Hi,

Are you sure it's CreateImage itself taking 2-3 minutes? If the delay comes from automatic layout code that runs before you export the image, you can call the ArrangeAsync methods of layout classes, available in .NET 4.5 builds of the assemblies.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
KillaChris19
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 8
Joined: Mar 9th, 2018
Re: Create Image Async
Reply #2 - Mar 19th, 2018 at 6:41am
Print Post  
Hello,
I'm already using the ArrangeAsync method.
But I'm sure that it is CreateImage, which takes that long. The diagram itself is complety printed. I have an extra option to save the Diagram as picture. So the user has to click on a button to start this process.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Create Image Async
Reply #3 - Mar 19th, 2018 at 9:29am
Print Post  
Hi,

What's your diagram.Bounds value at the time you click export? How many item in the diagram?

Regards,
Slavcho
  
Back to top
 
IP Logged
 
KillaChris19
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 8
Joined: Mar 9th, 2018
Re: Create Image Async
Reply #4 - Mar 19th, 2018 at 9:55am
Print Post  
There are 237 nodes and 231 links.

The height is 2320
The width is 36498
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Create Image Async
Reply #5 - Mar 19th, 2018 at 10:58am
Print Post  
A diagram with 500 nodes, 1000 links and your Bounds value exports for under a second in our tests, including saving the image to a file -

Code
Select All
diagram.Bounds = new Rect(0, 0, 36498, 2320);
....

DateTime start = DateTime.Now;
var img = diagram.CreateImage();

Utilities.SaveImage(img, "D:\\diagramImage.png");

TimeSpan ellapsed = DateTime.Now - start;

diagram.BackgroundImage = img;
MessageBox.Show(ellapsed.ToString()); 



What kind of nodes are you using, and to what image format are you saving the image?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Create Image Async
Reply #6 - Mar 19th, 2018 at 11:35am
Print Post  
We've reproduced it actually, we had a smaller Bounds value coming at a later point. It seems slowed down by internal RenderTargetBitmap creation, we'll try to create async version for upcoming release.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Create Image Async
Reply #7 - Apr 25th, 2018 at 9:12am
Print Post  
Our developer has just looked into this for adding to current release but sadly won't be available. Our measurements show the slowest part of CreateImage is the RenderTargetBitmap.Render call. There's a RenderTargetBitmap.RenderAsync method in the UWP framework which is missing from WPF, so we can't create async version in WPF control directly. We've also tried various Task and thread -based solutions but have problems with thread affinities there.

For time being try running image export as external process. E.g. you pass diagram's file name as argument to the child process, load a copy in diagram there and export, report export done to user once the process exits.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint