c#多屏截图。遮蔽画不上去,截取第二屏没法截图

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;
        //保留当前屏
        ScreenImage = GetDestopImage();
        //复制当前屏
        Image BackScreen = new Bitmap(ScreenImage);
        Graphics g = Graphics.FromImage(BackScreen);
        //画遮罩
        g.FillRectangle(mask, 0, 0, BackScreen.Width, BackScreen.Height);
        g.Dispose();
        //将有遮罩的图像作为背景
        this.BackgroundImage = BackScreen;

        //BackgroundImage = GetDestopImage();

        try
        {
            _selectCursor = new Cursor(Properties.Resources.Arrow_M.Handle);
        }
        catch { }
        Cursor = SelectCursor;

private Image GetDestopImage()
{
Rectangle rect = Screen.AllScreens[xy].Bounds;
Bitmap bmp = new Bitmap(
rect.Width, rect.Height, PixelFormat.Format32bppArgb);
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;
    }
c#

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问