Problem with image export

Hi! I have a problem.

Hi I have this code for export my diagram to image

`                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 scale = 2.0;
                    if (w > 2000) scale = 5000 / w;
                    if (h > 2000) scale = Math.Min(scale, 5000 / h);
                    w *= scale;
                    h *= scale;
                    this.myDiagram.Panel.MakeBitmap(new Size(w, h), 96, new Point(bounds.X, bounds.Y), scale, bmp =>
                    {
                        WriteableBitmap bitmap = new WriteableBitmap(bmp);
                        var img = bitmap.ToImage();
                        using (Stream stream = sd.OpenFile())
                        {
                            img.WriteToStream(stream);
                        }
                        MessageBox.Show("Exportación finalizada");
                    });
                }`

But when my diagram is very large I have one this error:

Can you help me please?

What are the actual values of w and h when you get the OutOfMemory error? Each bitmap might take w*h*4 bytes in memory.