This is a migrated thread and some comments may be shown as answers.

Export diagram as image without displaying it

9 Answers 154 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 24 Apr 2014, 12:58 PM
Here is my code:
var diagramToExportView = new DiagramToExportView();
//diagramToExportView.diagram is a RadDiagram, diagramToExportView is a WPF UserControl
diagramToExportView.diagram.Measure(new Size(640, 450));
diagramToExportView.diagram.Arrange(new Rect(new Size(640, 450)));
 
diagramToExportView.diagram.ExportToImage(stream, null, null, margin: _exportMargin,
                    backgroundBrush: new SolidColorBrush(Colors.White));

this seems working as expected: the stream contains a diagram image and nothing is shown / added to the visual tree.
The problem is that the diagram is not "completely" drawn, see the attached screenshots (expected vs actual): the additional connection geometries comes from this code (basically a custom connection):

public class MyConnection : RadDiagramConnection {
 
   protected override void UpdateGeometryOverride() {
            base.UpdateGeometryOverride();
 
            // draw geometry
     }
}

My guess is that Measure / Arrange calls don't triggers everything on the diagram's layout.
Any idea?

9 Answers, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 29 Apr 2014, 10:27 AM
Hello Manuel,
As far as we tested the UpdateGeometryOverride method is triggered by the Measure and Arrange calls so this should not be the problem. Could you please try to override the CreateGeometry method and return your custom geometry there:
protected override Geometry CreateGeometry(BridgeType bridgeType, bool roundedCorners)
{
    // Create your geometry and return it.
    return newGeometry;
}
(note: if you just create a geometry and set it as the Geometry property it won't update the visual path (this is by design))
I hope I was able to help you and if you have more questions feel free to ask.

Regards,
Zarko
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Manuel
Top achievements
Rank 1
answered on 29 Apr 2014, 03:06 PM
Hello Zarko,
overriding CreateGeometry fixed the layout issue: now the geometry is rendered as expected.
Strangely enough for some reason, it seems that your solution leaks a lot of memory (~ 100MB per run on a quite big sample are never collected).

My previous workaround was to create an invisible/disabled/modal dialog with the usercontrol as content:
var window = new TimeoutWindow(2000) // a simple Window with an auto-close timer
{
    Content = diagramToExportView,
    Visibility = Visibility.Collapsed,
    Width = 0,
    Height = 0,
    WindowStyle = WindowStyle.None,
    ShowInTaskbar = false,
    ShowActivated = false,
    IsEnabled = false,
    WindowStartupLocation = WindowStartupLocation.Manual,
    Left = SystemParameters.VirtualScreenWidth+ 100
};
 
window.ShowDialog();

Of course this is absolutely terrible, but for some reason this way the memory is collected as expected...
0
Zarko
Telerik team
answered on 30 Apr 2014, 11:43 AM
Hello Manuel,
This is a strange issue and I'd like to ask you for some more information:
1) What's your dll version
2) Have you tried to profile your application with JustTrace, Ants or something similar ?
I'm asking this because as far as I tested the RadDiagram instances are cleared by the GC after the export method (well, they are not cleared right after that but this is part of the internal GC logic and if you force a collection with GC.Collect(); everything is cleared).
I've attached my sample project so you could examine it and if you want you could send us your project so that we could test it.

Regards,
Zarko
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Manuel
Top achievements
Rank 1
answered on 30 Apr 2014, 04:16 PM
Yes, it's really really strange...

I've profiled the application (JustTrace) and the results I was refering to comes from a memory profiling session: RadConnections / RadShapes and so on are not collected using your solution...

DLLs v. 2013.3.1016.40.
0
Peshito
Telerik team
answered on 02 May 2014, 12:02 PM
Hi Manuel,

Could you verify that the issue still persists with the latest version of our controls as we have recently fixed an issue related to a memory leak which is now resolved. If the issue is still reproducible even with the latest DLLs, would you please share your sample project so we could make some tests locally and locate where the issue comes from. As this is a forum thread, you will need to share the project using a third party website for uploading and sharing files.

Regards,
Peshito
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Manuel
Top achievements
Rank 1
answered on 19 May 2014, 01:38 PM
I've upgraded my project to 2014.1.331 (.NET 4.0) but the issue is not solved: attached a rough memory usage diagram (three executions). As you can see, the "hacked" version releases the memory as expected, while the "regular" one not.

Here the only difference between runs, "DiagramToExportView" is a usercontrol containing only a RadDiagram:

private static void RefreshDiagram(DiagramToExportView diagramToExportView) {
 
    /* HACK */
    var window = new TimeoutWindow(2000)
    {
        Content = diagramToExportView,
        Visibility = Visibility.Collapsed,
        Width = 0,
        Height = 0,
        WindowStyle = WindowStyle.None,
        ShowInTaskbar = false,
        ShowActivated = false,
        IsEnabled = false,
        WindowStartupLocation = WindowStartupLocation.Manual,
        Left = SystemParameters.VirtualScreenWidth+ 100
    };
 
    window.ShowDialog();
 
    /* REGULAR */
    diagramToExportView.diagram.Measure(new Size(640, 450));
    diagramToExportView.diagram.Arrange(new Rect(new Size(640, 450)));
}
0
Peshito
Telerik team
answered on 22 May 2014, 06:51 AM
Hi Manuel,

The fixed issue I mentioned in my earlier reply is fixed after the Q1 2014 SP1 release you are actually using. The fix is included in the LIBs(Last Internal Build) after that. Could you please verify that the issue is still reproducible in your application using the DLLs from the Last Internal Build. You can find the latest LIB under your account.

Regards,
Peshito
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Manuel
Top achievements
Rank 1
answered on 26 May 2014, 08:12 AM
I've updated to 2014.1.519.40 but the strange behavior is still there: the "regular" version leaks memory while the "hacked" one seems to be fine...
Obviously the hack is doing some additional disposal I'm not aware of: do you guys have some ideas?
Is there something else I can try?
Tx
0
Peshito
Telerik team
answered on 28 May 2014, 11:06 AM
Hi Manuel,

I tried to reproduce the issue, using the project earlier provided by my colleague Zarko but to no avail. Could you please send us a sample runnable project isolation the issue. This way working on that project locally and being able to reproduce it, we will be able to provide you with a solution. You can either edit the project Zarko sent you earlier or send us a copy of your own.

As this is a forum thread and you are not allowed to upload files here unless you submit a support ticket thread, you can use a third party website for uploading and sharing files.

Regards,
Peshito
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Diagram
Asked by
Manuel
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Manuel
Top achievements
Rank 1
Peshito
Telerik team
Share this question
or