0

I save a a plot to a png file from my image. I use a code snippet I found on the net:

Rect bounds = LayoutInformation.GetLayoutSlot(SensorPanelGraph);
var bitmap = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, PixelFormats.Pbgra32);

DrawingVisual dv = new DrawingVisual();

using (DrawingContext dc = dv.RenderOpen())
{
      VisualBrush vb = new VisualBrush(SensorPanelGraph);
      dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
}

bitmap.Render(dv);
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\Graph.png";
using (FileStream outStream = new FileStream(path, FileMode.Create))
{
     PngBitmapEncoder enc = new PngBitmapEncoder();
     enc.Frames.Add(BitmapFrame.Create(bitmap));
     enc.Save(outStream);
}

What I would like to do now is to put a Legend on the upper right corner of my final image. I can use the same code to generate an image of my Legend on the GUI, but I have no clue how to overlay it in the upper right corner of my graph png.

Thanks in advance!

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Tamaska Janos
  • 61
  • 1
  • 6
  • 1
    How about another DrawRectangle call with a VisualBrush that holds the legend? – Clemens Jul 28 '15 at 12:34
  • So far so good! It works, I only need to manipulate the position of the second rectangle. Now it draws at the (0,0) coordinate. The upper left corner. – Tamaska Janos Jul 28 '15 at 12:48
  • Ok, tsolved. Quite obvious actually: dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size)); the Point parameter is the origin. – Tamaska Janos Jul 28 '15 at 13:29
  • I still have one step to have a perfect code. I Started a new question to keep it clean: http://stackoverflow.com/questions/31677823/visualbrush-for-elements-with-scrollbar-in-wpf – Tamaska Janos Jul 28 '15 at 13:32

0 Answers0