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

Export to PNG

1 Answer 91 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Xiao
Top achievements
Rank 1
Xiao asked on 20 Nov 2012, 07:10 PM
Hello 

I'm trying to export shapes to a png file using exportToImage() method in RadDiagram.
However, the generated png image is all black, that is every pixel is black.
The RadDiagram I generated is not in the visual tree.

I did something like this:
var diagram = new RadDiagram();
diagram.Load(shapeData);
 
using (FileStream stream = new FileStream("C:\\test\\test-1.png", FileMode.OpenOrCreate, FileAccess.Write))
{
    diagram.ExportToImage(stream);
}

Is it because RadDiagram is not in the visual tree? Is there a work around?

Thanks

1 Answer, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 23 Nov 2012, 03:25 PM
Hello Xiano,
The problem is that the RadDiagram is not in the visual tree and the styles and templates are not applied. Until the diagram loads (enters the visualTree) there are no shapes (containers) generated and basically there's nothing to export. 
You could try something like this:
var diagram = new RadDiagram();
diagram.Load(shapeData);
 
this.LayoutRoot.Children.Add(diagram);
using (FileStream stream = new FileStream("C:\\test\\test-1.png", FileMode.OpenOrCreate, FileAccess.Write))
{
    diagram.ExportToImage(stream);
}
this.LayoutRoot.Children.Remove(diagram);
If you have further questions please feel free to ask.

Greetings,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Diagram
Asked by
Xiao
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Share this question
or