使用WPF中的PngBitmapEncoder覆盖图像

时间:2015-07-28 12:00:28

标签: c# wpf

我将图片保存到我的图片中的png文件中。我使用网上找到的代码片段:

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);
}

我现在要做的是在最终图像的右上角放置一个图例。我可以使用相同的代码在GUI上生成我的Legend的图像,但我不知道如何将它叠加在我的图形png的右上角。

提前致谢!

0 个答案:

没有答案