c#有关多屏截图的问题遮蔽画不到第二个屏
星海穿梭者 2017-08-01 05:10:35 SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
//双缓冲绘制,避免闪烁
//this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
// 判断屏幕
XY();
drawToolsControl.Visible = false;
colorSelector.Visible = false;
textBox.Visible = false;
this.TopMost = true;
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.None;
Bounds = Screen.AllScreens[xy].Bounds;
this.FormBorderStyle = FormBorderStyle.None;
this.DesktopBounds = Screen.AllScreens[xy].Bounds;
//保留当前屏
ScreenImage =GetDestopImage();
//复制当前屏
Image BackScreen = new Bitmap(ScreenImage);
Graphics g = Graphics.FromImage(BackScreen);
//画遮罩
g.FillRectangle(mask, 0, 0, BackScreen.Width, BackScreen.Height);
//g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[xy].Bounds.Size);
g.Dispose();
//将有遮罩的图像作为背景
//BackgroundImage = ScreenImage;
//BackgroundImage = GetDestopImage();
BackgroundImage =GetDestopImage();
try
{
_selectCursor = new Cursor(Properties.Resources.Arrow_M.Handle);
}
Screen sr = Screen.AllScreens[xy];
Rectangle rect = sr.Bounds;
Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format64bppPArgb);
Graphics g = Graphics.FromImage(bmp);
IntPtr gHdc = g.GetHdc();
IntPtr deskHandle = NativeMethods.GetDesktopWindow();
IntPtr dHdc = NativeMethods.GetDC(deskHandle);
NativeMethods.BitBlt(
gHdc,
0,
0,
Width,
Height,
dHdc,
0,
0,
NativeMethods.TernaryRasterOperations.SRCCOPY);
NativeMethods.ReleaseDC(deskHandle, dHdc);
g.ReleaseHdc(gHdc);
return bmp;