Export to PNG

2 posts, 0 answers
  1. Xiao
    Xiao avatar
    6 posts
    Member since:
    Jul 2011

    Posted 20 Nov 2012 Link to this post

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

    Posted 23 Nov 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top