我正在使用 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表格的快照。任何的想法。谢谢。