Export diagram as image without displaying it

10 posts, 0 answers
  1. Manuel
    Manuel avatar
    32 posts
    Member since:
    Sep 2013

    Posted 24 Apr 2014 Link to this post

    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?
  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 29 Apr 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Manuel
    Manuel avatar
    32 posts
    Member since:
    Sep 2013

    Posted 29 Apr 2014 in reply to Zarko Link to this post

    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...
  5. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 30 Apr 2014 Link to this post

    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.
     
  6. Manuel
    Manuel avatar
    32 posts
    Member since:
    Sep 2013

    Posted 30 Apr 2014 in reply to Zarko Link to this post

    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.
  7. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 02 May 2014 Link to this post

    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.
     
  8. Manuel
    Manuel avatar
    32 posts
    Member since:
    Sep 2013

    Posted 19 May 2014 in reply to Peshito Link to this post

    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)));
    }
  9. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 22 May 2014 Link to this post

    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.
     
  10. Manuel
    Manuel avatar
    32 posts
    Member since:
    Sep 2013

    Posted 26 May 2014 Link to this post

    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
  11. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 28 May 2014 Link to this post

    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.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready