private void TakeScreenShot(String fileName)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(this);
double dpi = 96d;
RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height,
dpi, dpi, PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(this);
dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
}
renderBitmap.Render(dv);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
using (FileStream file = File.Create(fileName))
{
encoder.Save(file);
}
} }
C#截图
最新推荐文章于 2023-08-29 11:38:24 发布