Export to image. Goxam - Silverlight

Hi, I’m trying to export to an image diagram. Look at several examples, but as work with Silverlight 5 does not have the PngBitmapEncoder. As I can do? I’m pretty new at this, could give me some example please?
Thank you

http://forum.nwoods.com/forum/forum_posts.asp?TID=3512

Yes, you can do that. The process starts with calling DiagramPanel.MakeBitmap. Typically you want to limit how large the bitmap gets, because you don't want to use up too much memory. You'll want to decide the maximum size to use for your application.<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

<p style=“margin: 0in 0in 0pt;” =“Mso”><o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> Rect bounds =
myDiagram.Panel.DiagramBounds;<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> double w =
bounds.Width;<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> double h =
bounds.Height;<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> // calculate
scale so maximum width or height is 2000:<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> double s = 1.0;<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> if (w > 2000)
s = 2000/w;<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> if (h > 2000)
s = Math.Min(s, 2000/h);<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> w = Math.Ceiling(w

  • s);<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> h =
Math.Ceiling(h * s);<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>
myDiagram.Panel.MakeBitmap(new Size(w, h), 96, new Point(bounds.X,
bounds.Y), s,<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> bmp => {<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> … use the
BitmapSource … to write the image file<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> });<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”><o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>In WPF you could do:<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>
PngBitmapEncoder png = new PngBitmapEncoder();<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>
png.Frames.Add(BitmapFrame.Create(bmp));<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> using
(System.IO.Stream stream = System.IO.File.Create(filename)) {<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>
png.Save(stream);<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> }<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”><o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>Silverlight does not have built-in support for writing
any kinds of image files. You’ll need to use a separate package such as .NET Image
Tools, available from codeplex.com. I have not tried the following code, so I cannot vouch
for its success:<o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>
WriteableBitmap bitmap = new WriteableBitmap(bmp);<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”>
ImageTools.Image img = bitmap.ToImage();<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> using
(System.IO.Stream stream = System.IO.File.Create(filename)) {<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> new
ImageTools.IO.Png.PngEncoder().Encode(img, stream);<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Mso”> }

Sorry but how save a BitmapSource ?

I just posted the code to do exactly that.

But if i want to save with open save dialog?

Then use the SaveFileDialog or other functionality that Silverlight gives you.
Such issues are beyond the scope of GoXam.

Yes is true!.
I can, i give the code:

        SaveFileDialog sd = new SaveFileDialog();
        sd.Filter = "Imagenes (*.bmp)|*.bmp";
        if (sd.ShowDialog() == true)
        {
            Rect bounds = myDiagram.Panel.DiagramBounds;
            double w = bounds.Width;
            double h = bounds.Height;
            double s = 1.0;
            if (w > 2000) s = 2000 / w;
            if (h > 2000) s = Math.Min(s, 2000 / h);
            w = Math.Ceiling(w * s);
            h = Math.Ceiling(h * s);
            myDiagram.Panel.MakeBitmap(new Size(w, h), 96, new Point(bounds.X, bounds.Y), s, bmp =>
            {
                WriteableBitmap bitmap = new WriteableBitmap(bmp);
                var img = bitmap.ToImage();
                using (Stream stream = sd.OpenFile())
                {
                    img.WriteToStream(stream);
                }
            });
        }