Save image problem #2


How can I explain about this.

First of all, Diagram’s size is fixed by 547x418.

User can set up DiagramPanel’s size using FixedBounds(ex. 1024x768)

I set DiagramPanel’s background up in White, but it doesn’t work.

1. Writablebitmap to JPG case.

Saved image’s background is black.

I set Diagram’s background up in White.

Saved image : Diagram(viewport) area(5247X428) is white, the other is still black.

Moreover, Nodes located out of viewport are missing(just name-text remaiend)

2.Writablebitmap to PNG case.

Because PNG support alpha channel, image’s background is tranparent. But Nodes located out of viewport are still missing.

I found one solution in PNG case.

After I changed DiagramPanel’s Scale fit to viewport. I could get a whole image on transparent background.

In this case, programatical scaling didn’t work,

scaling must be performed by user action.

And saved image is too large (1024x768 - over 3MB)

Could you post a “Image saving” example code?

I couldn’t find the way. T_T

Exactly what platform and version and which GoXam version are you using?

Have you tried using the latest version?


os - windows7

visualstudio 2010

It seems that Silverlight renders the bitmap asynchronously, so if you write the image file too early, it won’t have everything that you would expect. So you should call the overloaded method DiagramPanel.MakeBitmap that takes an Action argument. You can do your file-writing in that Action, or afterwards.

using MakeBitmap in Silverlight

I’m not sure that that will address your issues with the Diagram.Background brush, but it might.

OOPS, I see. I should use Action!

Thanks a lot!

JPG’s background is still black. Writablebitmap has alpha channel,do you know how to set DiagramPanel’s background?

API document says:

DiagramPanel Class


Because DiagramPanel is a Panel, you can define the layers of this panel in XAML by placing them nested within the definition of the element. If you do not define any layers explicitly, the InitializeLayers method will create the standard nine layers: “Background” nodes and links, default ("") nodes and links, “Foreground” nodes and links, “Tool” nodes and links, and “Adornment” nodes.

This class is also responsible for mouse input. It redirects mouse events to the Diagram’s Diagram.CurrentTool.

You may not apply any transforms to a Layer; that is reserved for GoXam’s use.

This panel’s Background is also reserved for GoXam’s use.

MakeBitmap temporarily sets the DiagramPanel.Background to be the same as the Diagram.Background.

We’ll investigate this some more.

I added an element so that I could see the resulting bitmap in my Silverlight app:

<Border BorderBrush="Black" BorderThickness="1"> <Image x:Name="myBitmap" /> </Border>
And I added a Button that executes:

[code] private void Button_Click(object sender, RoutedEventArgs e) {
myDiagram.Background = new SolidColorBrush(Colors.Yellow);

  Rect bounds = myDiagram.Panel.DiagramBounds;
  double w = bounds.Width;
  double h = bounds.Height;
  // calculate scale so maximum width or height is 200:
  double s = 1.0;
  if (w > 200) s = 200/w;
  if (h > 200) s = Math.Min(s, 200/h);
  w *= s;
  w = Math.Ceiling(w);
  h *= s;
  h = Math.Ceiling(h);
  BitmapSource bmp = myDiagram.Panel.MakeBitmap(new Size(w, h), 96, new Point(bounds.X, bounds.Y), s);
  myBitmap.Source = bmp;

Sure enough, the whole background of the image shows bright yellow, even the portions of the diagram that are outside of the current viewport.