簡體   English   中英

要捕獲最小化窗口的屏幕截圖

[英]Want to capture screen shot of minimize window

我正在使用MDI應用程序。 在最小化任何sdi形式之前,我想捕獲沒有標題欄的屏幕快照。我的代碼正在工作,但是我捕獲的圖像不清楚但有點晦澀。 這樣我做到了。 這是我的代碼。

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)
        {

            if (_lastSnapshot == null)
            {
                _lastSnapshot = new Bitmap(100, 100);
            }

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

                float scaleX = 1;
                float scaleY = 1;
                if (ClientRectangle.Width > ClientRectangle.Height)
                {
                    scaleY = (float)ClientRectangle.Height / ClientRectangle.Width;
                }
                else if (ClientRectangle.Height > ClientRectangle.Width)
                {
                    scaleX = (float)ClientRectangle.Width / ClientRectangle.Height;
                }
                tipGraphics.DrawImage(windowImage, 0, 0, 100 * scaleX, 100 * scaleY);
            }
        }

因此,指導我如何獲取sdi表格,使其更加清晰和突出。 任何想法。 謝謝。

您縮放圖片,任何縮放-無論是放大還是縮小-都會導致圖像質量降低。 除了縮放圖像外,我還可以獲取窗口的寬度和高度,使用該尺寸創建一個新的位圖,並最終以相同的尺寸繪制圖像。

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

或接近上面的內容-我實際上無法測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM