Export Diagram to a list of images

7 posts, 0 answers
  1. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 17 Dec 2015 Link to this post

    Hi,

    I try to export my diagram to a list of images without success.

    I use the following method : (the class inherit from RadDiagram)

    public List<System.Drawing.Image> GetImages()
            {
                List<System.Drawing.Image> list = new List<System.Drawing.Image>();
                RadDiagramPagesInfo pagesInfo = this.CalculatePages(BackgroundPageGrid.GetPageSize(this), new Thickness());
                pagesInfo.Background = this.Background;
                pagesInfo.Dpi = 96d;
                foreach (WriteableBitmap writeableBitmap in pagesInfo.Pages)
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        PngBitmapEncoder encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(writeableBitmap));
                        encoder.Save(stream);
                        list.Add(System.Drawing.Image.FromStream(stream));
                    }
                }
                return (list);
            }

    The problem is that pagesInfo.Pages is empty !

     Here is the call !

    DiagramGraphSource graphSource = new DiagramGraphSource();
                graphSource.LoadProcedureSteps(steps.Cast<IStep>().ToList());
                diagram.GraphSource = graphSource;
                diagram.Measure(new System.Windows.Size(1000, 1000));
                diagram.Arrange(new Rect(new System.Windows.Size(1000, 1000)));
     
                 
     
                return (diagram.GetImages().Select(x => new ImageObject { Image = x}).ToList());

    Thanks a lot

     
     
     
  2. Milena
    Admin
    Milena avatar
    204 posts

    Posted 18 Dec 2015 Link to this post

    Hi Geoffrey,

    To achieve this you can use the diagram's method ExportToImage, where you can control the type and size of the created image along with the area of the diagram that should be exported. For your scenario where you need to export the diagram to more than one image, you can call the method more than once and define the portion of the diagram to be exported as you can see in our help topic Image Export:
    private void ExportToImage(object sender, RoutedEventArgs e)
    {
        using (var stream = File.Open(@"c:\temp\xDiagram.png", FileMode.Create))
        {
            xDiagram.ExportToImage(stream,null,new Rect(0,0,100, 1000),new Size(1000,1000));
        }
    }

    I hope this information helps. Please let us know if any further assistance is needed.

    Regards,
    Milena
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 23 Dec 2015 in reply to Milena Link to this post

    Hello,

    It works with ExportToImage.

    But the custom router is not correct in the generated images (see attached files).

    Thanks,
    Geoffrey

     
     
     
  5. Peshito
    Admin
    Peshito avatar
    497 posts

    Posted 24 Dec 2015 Link to this post

    Hi Geoffrey,

    I tried reproducing the exporting issue but to no avail. I played several scenarios and all of them exported as expected. Could you share a sample runnable project reproducing the issue so I could debug it locally and provide you with a possible solution? As this a forum post and attaching is not allowed you could submit a support ticket regarding the same thread or use a third party web site for files sharing.

    Regards,
    Peshito
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 12 Jan Link to this post

    Sorry for my late answer,

    You can find the project here :

    https://transfer-vinci-energies.nextsend.com/download/mrLcyt+635lh7c243bOgibO4367YtKK7m8rrdaxSZ7CUgbJ_ZlWojqJvmA==/

    The custom router is not called.
    The button export in memory diagram to desktop.

    Thanks in advance.
    It's very important to solve this problem for our customers. 

     
    Best regards,
    Geoffrey

     

     

     
     
     
  7. Milena
    Admin
    Milena avatar
    204 posts

    Posted 14 Jan Link to this post

    Hello Geoffrey,

    Thank you for the project provided. I was able to reproduce the described behavior locally.

    The issue is caused by the fact that when you set RouteConnections property of the diagram to true, the GraphSource is not yet populated and the connections are not created. The result is that the routing is actually not enabled (this is why the custom router is not called).
    However, I can suggest you 2 approaches to resolve this: 
    1. To set  RouteConnections property after you create the GraphSource: 
    private void ButtonBaseOnClick(object sender, RoutedEventArgs e)
            {
                Diagram diagram = new Diagram();
                ...
               
                DiagramGraphSource graphSource = new DiagramGraphSource();
                diagram.GraphSource = graphSource;
                graphSource.LoadProcedureSteps(steps);
     
                //enable routing
                diagram.RoutingService.AutoUpdate = true;
                ....
    }

    2. To set Route property of the RadDiagrmConnection in style: 
    <Style TargetType="telerik:RadDiagramConnection" BasedOn="{StaticResource {x:Type telerik:RadDiagramConnection}}" >
            <Setter Property="Route" Value="True" />
             ....
    </Style>

    I hope this information helps.

    Regards,
    Milena
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
     
  8. Geoffrey
    Geoffrey avatar
    48 posts
    Member since:
    Mar 2013

    Posted 14 Jan Link to this post

    Thanks for your reply.

    It works great :-)
Back to Top
UI for WPF is Visual Studio 2017 Ready