如何捕获包含标题栏的窗口快照

问题描述 投票:0回答:1

下面是我的例程,该例程运行良好,但该例程未生成包含标题栏的窗口图像。所以指导我我需要更改代码。

protected override void WndProc(ref Message m)
{

            if (m.Msg == WM_COMMAND && m.WParam.ToInt32() == SC_MINIMIZE)
            {
                OnMinimize(EventArgs.Empty);
            }

            base.WndProc(ref m);
}

protected virtual void OnMinimize(EventArgs e)
{
    Rectangle r = this.RectangleToScreen(ClientRectangle);

    if (_lastSnapshot == null)
    {
        _lastSnapshot = new Bitmap(r.Width, r.Height);
    }

    using (Image windowImage = new Bitmap(r.Width, r.Height))
    using (Graphics windowGraphics = Graphics.FromImage(windowImage))
    using (Graphics tipGraphics = Graphics.FromImage(_lastSnapshot))
    {
        windowGraphics.CopyFromScreen(new Point(r.Left, r.Top), new Point(0, 0), new Size(r.Width, r.Height));
        windowGraphics.Flush();

        tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height);
    }
}

更新

我们的代码有效,但左上角有些不正确。所以在这里我要上传使用ur代码生成的图像。请看看并告诉我我需要在代码中修复的问题。表格宽度不正确。谢谢“在此处输入图像描述”“ >>

更新
    Bitmap bmp = new Bitmap(this.Width, this.Height);
    this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
    bmp.Save(@"d:\Zapps.bmp", ImageFormat.Bmp);

下面是我的例程,该例程运行良好,但该例程未生成包含标题栏的窗口图像。所以指导我我需要更改代码。受保护的覆盖无效WndProc(ref Message ...

c# screenshot
1个回答
0
投票

简单地获得标题栏的高度,并将其添加到要捕获的区域的高度(并从图像的当前顶部减去它-检查下面的源以进行更改):

© www.soinside.com 2019 - 2024. All rights reserved.