How big are the DiagramBounds.Width and Height – maybe they are too big?
When are you looking at the image? Is this for Silverlight or for WPF? You may need to use the Action argument to “look” at the image only after rendering has finished.
There are a lot of posts about MakeBitmap in this forum that might be able to help.
Rect b = uxdgm_Diagram.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 image = uxdgm_Diagram.Panel.MakeBitmap(newSize(w, h), 96, newPoint(b.X, b.Y), s, bmp =>
{
var pos = uxdgm_Diagram.Panel.Position;
uxdgm_Diagram.Panel.Position =newPoint(pos.X, pos.Y +1);
uxdgm_Diagram.Panel.Position = pos;
});
FileStream stream =newFileStream(@"c:\temporal\new.png", FileMode.Create);
PngBitmapEncoder encoder =newPngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(image));
encoder.Save(stream);
stream.Close();
You can only look at the contents of the bitmap image only when the Action is called or later. So you need to move that file-writing code into the Action/lambda expression.
Hello. I was probe the code and work in local, but when i excutes on server (deploy xap) i found a exception, any ideas???
I was modified the code, but exist the error:
privatevoid DoExportToImageAction()
{
try
{
Rect b = uxdgm_Diagram.Panel.DiagramBounds;
double w = b.Width;
double h = b.Height;
double scale =1.0;
if (w >2000) scale =2000/ w;
if (h >2000) scale =Math.Min(scale, 2000/ h);
w *= scale;
h *= scale;
var image = uxdgm_Diagram.Panel.MakeBitmap(newSize(w, h), 96, newPoint(b.X, b.Y), scale, bmp =>
{
var pos = uxdgm_Diagram.Panel.Position;
uxdgm_Diagram.Panel.Position =newPoint(pos.X, pos.Y +1);
uxdgm_Diagram.Panel.Position = pos;
// obtenemos dialogSaveFileDialog l_dialog =newSaveFileDialog();
l_dialog.DefaultExt =cSimulation.kPngFilster;
l_dialog.Filter =cSimulation.kPngFilster;
bool? dialogResult = l_dialog.ShowDialog();
if (dialogResult ==true)
{
try
{
using (System.IO.Stream fileStream = l_dialog.OpenFile())
{
PngBitmapEncoder encoder =newPngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
encoder.Save(fileStream);
}
}
catch (Exception p_ex)
{ RtcUtils.SendErrorReportToServer(p_ex, cMessageError.cErrorExportingToImage); }
}
});
} // try// Registramos el error en el servidorcatch (Exception pException)
{ RtcUtils.SendErrorReportToServer(pException, cMessageError.cErrorExportingToImage); }
}
THE ERROR:
EX_MESSAGE: Los cuadros de diálogos deben ser iniciados por el usuario.
EX_STACKTRACE: en System.Windows.Controls.SaveFileDialog.ShowDialogInternal(Window owner)
en SLRTC1201.Views.Editor.b__ab(BitmapSource bmp)
en Northwoods.GoXam.DiagramPanel.#sb.#FK()
en Northwoods.GoXam.DiagramPanel.#sb.#OM()
EX_INNER_EX_MESSAGE:
ERR_CUSTOM_MSG: 195.235.88.11
EX_INNER_EX_STACKTRACE:
Yes, that is a feature of Silverlight security: the user has to invoke a “Save File” dialog directly. I wonder if you need to have the user choose the file beforehand.
You must vinculate this code with event mouse, by example a click event. You must create open dialog… and after use the code above. You can not do work if refactor in another function, the open dialog must execute directly vinculated to mouse event. (Segurity exception of silverlight)