Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
135
Save orgChart as image
posted

Is there a way to save the orgchart as an image?

Because the the non public property NodesPanel has a property PreviewImage?

Or is there a way to access the OrgchartNodesPanel, I think then it is possible to create a writable bitmap myself?

Greetings,

Amko Hartman
Perigon Vision bv
http://www.perigonvision.eu

 

Parents
No Data
Reply
  • 135
    Suggested Answer
    posted

    Hi guys,

    I managed to save the OrgChart as an image, see the code below.

    public static void SaveOrgChartAsImage(XamOrgChart orgChart, SaveFileDialog dialog)
            {
                try
                {
                    //set overview plus detail pane visibility
                    orgChart.OverviewPlusDetailPaneVisibility = Visibility.Collapsed;

                    int width = (int)orgChart.ActualWidth;
                    int height = (int)orgChart.ActualHeight;

                    WriteableBitmap bitmap = new WriteableBitmap(width, height);
                    bitmap.Render(orgChart, new TranslateTransform());
                    bitmap.Invalidate();

                    EditableImage imageData = new EditableImage(bitmap.PixelWidth, bitmap.PixelHeight);

                    for (int y = 0; y < bitmap.PixelHeight; ++y)
                    {

                        for (int x = 0; x < bitmap.PixelWidth; ++x)
                        {

                            int pixel = bitmap.Pixels[bitmap.PixelWidth * y + x];
                            imageData.SetPixel(x, y,

                            (byte)((pixel >> 16) & 0xFF),
                            (byte)((pixel >> 8) & 0xFF),

                            (byte)(pixel & 0xFF), (byte)((pixel >> 24) & 0xFF));
                        }
                    }

                    // Save it to disk
                    Stream pngStream = imageData.GetStream();

                    StreamReader sr = new StreamReader(pngStream);
                    byte[] binaryData = new Byte[pngStream.Length];

                    long bytesRead = pngStream.Read(binaryData, 0, (int)pngStream.Length);
                    using (Stream stream = dialog.OpenFile())
                    {
                        stream.Write(binaryData, 0, binaryData.Length);
                    }
                }
                finally
                {
                    orgChart.OverviewPlusDetailPaneVisibility = Visibility.Visible;
                }
            }

     

    Greetings,

    Amko Hartman

Children