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 HartmanPerigon Vision bvhttp://www.perigonvision.eu
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; } }
Amko Hartman
I forgot to add the EditableImage class. It is attached in this post.
Hi Amko
I am really sorry but now I seem to be missing the PngEncode class.
I do appreciate your help on this.
Andrew
Sorry for not posting all the correct files. I made a new zip this should contain all the files.
I have now got his working - many thanks!
Am I correct that the image should always be created a a Windows bitmap (*.bmp) file, or is there any way of saving it as a jpeg or png?
Regards
Ok - I will check.
Many thanks for your excellent response
Hi , Andrew
I save the images with the png extension and it works oke. If they are realy png files, I am not sure I am not deep anough in the stuff so I could say. The png Encoder sould make a png file of it.