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

Export Diagram to a list of images

6 Answers 47 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Geoffrey
Top achievements
Rank 1
Geoffrey asked on 17 Dec 2015, 02:29 PM
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

 
 
 

6 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 18 Dec 2015, 11:52 AM
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
0
Geoffrey
Top achievements
Rank 1
answered on 23 Dec 2015, 08:52 AM
Hello,

It works with ExportToImage.

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

Thanks,
Geoffrey

 
 
 
0
Peshito
Telerik team
answered on 24 Dec 2015, 02:49 PM
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
0
Geoffrey
Top achievements
Rank 1
answered on 12 Jan 2016, 03:56 PM

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

 

 

 
 
 
0
Milena
Telerik team
answered on 14 Jan 2016, 11:55 AM
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
 
0
Geoffrey
Top achievements
Rank 1
answered on 14 Jan 2016, 02:40 PM
Thanks for your reply.

It works great :-)
Tags
Diagram
Asked by
Geoffrey
Top achievements
Rank 1
Answers by
Milena
Telerik team
Geoffrey
Top achievements
Rank 1
Peshito
Telerik team
Share this question
or