Print or ScreenShot in SL

Hi, i want to know if is possible to print or capture the screen in a jpeg or png image of the full diagram


You can call Diagram.Panel.MakeBitmap to produce a bitmap.

Silverlight doesn’t seem to have a way of generating JPEG or PNG files. But you could try using .NET Image Tools.

Thanks, but can you show me how can i take the bitmap of all the parts of the diagram?

i use this code but doesn’t work:

BitmapSource Immagine = myDiagram.Panel.MakeBitmap(new Size(4000,3000),72,new Point(),100);


100 isn’t the scale argument that you want to use – you probably got a blank bitmap. The normal scale is 1.0.

Also you want to use the DiagramPanel.DiagramBounds. Something like:

Rect b = myDiagram.Panel.DiagramBounds; var bmp = myDiagram.Panel.MakeBitmap(new Size(b.Width, b.Height), 96, new Point(b.X, b.Y), s);
However, if your diagram is large, the bitmap will get too big to fit into memory. To limit the size of the bitmap while still getting all of the diagram drawn in the bitmap, you need to decrease the scale correspondingly. Here’s one way to limit the bitmap to 2000x2000:

Rect b = myDiagram.Panel.DiagramBounds; double w = b.Width; double h = b.Height; double s = 1.0; if (w > 2000) s = 2000/w; if (h > 2000) s = Math.Min(s, 2000/h); w *= s; h *= s; var bmp = myDiagram.Panel.MakeBitmap(new Size(w, h), 96, new Point(b.X, b.Y), s);

thank you very much!!

By the way, it turns out that Silverlight renders the contents of the Bitmap asynchronously. So at the time that MakeBitmap returns, the bitmap may not have all of the nodes and links that you expect.

If you are just going to display the bitmap as part of your application, I don’t think you’ll run into troubles. But if you are going to process the bitmap, as you would if you are generating a JPEG or PNG image, then you need to wait.

To make it easier to wait, we have added an overloaded MakeBitmap method in version 1.1.9 that takes an additional final argument of type Action. Do your image processing in that action, or after that action is called.

In any case, if you are using version 1.1, I recommend using the 1.1.9 (or later) DLL: latest releases.

Thank you very much.
Now it’s working.

i’ve passed the function into the action parameter in makbitmap function, something like this:


BitmapSource Img = myDiagram.Panel.MakeBitmap(new Size(w, h), 96, new Point(b.X, b.Y), s,BitmapConversion);


private void BitmapConversion(BitmapSource Img)


My screenshot now is very pretty ;)


best regards

Hello Simone.

Exactly, what did you do in BitmapConversion??. I copied the rgautam´s code, but i get a blank image. Thanks