public class SnapshotHelper
{
public static BitmapSource Capture(Rect absoluteControlRect)
{
using (var screenBmp = new System.Drawing.Bitmap(
(int)absoluteControlRect.Width,
(int)absoluteControlRect.Height,
PixelFormat.Format32bppArgb))
{
using (var bmpGraphics = System.Drawing.Graphics.FromImage(screenBmp))
{
bmpGraphics.CopyFromScreen((int)absoluteControlRect.Left, (int)absoluteControlRect.Top, 0, 0, screenBmp.Size);
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
screenBmp.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
}
}
public static Rect GetAbsoltutePlacement(FrameworkElement visual)
{
Point absolutePos = visual.PointToScreen(new Point(0, 0));
return new Rect(absolutePos.X, absolutePos.Y, visual.ActualWidth, visual.ActualHeight);
}
}
Использование:
var rect = SnapshotHelper.GetAbsoltutePlacement(yourControl);
var image = SnapshotHelper.Capture(rect);