我也发过类似的帖子,但是没有找到满意的答案

解决方案 »

  1.   

    [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
    private static extern bool BitBlt(
    IntPtr hdcDest, // handle to destination DC
    int nXDest,  // x-coord of destination upper-left corner
    int nYDest,  // y-coord of destination upper-left corner
    int nWidth,  // width of destination rectangle
    int nHeight, // height of destination rectangle
    IntPtr hdcSrc,  // handle to source DC
    int nXSrc,   // x-coordinate of source upper-left corner
    int nYSrc,   // y-coordinate of source upper-left corner
    System.Int32 dwRop  // raster operation code
    ); [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
    private static extern IntPtr  CreateDC(
                  string lpszDriver,        // driver name
      string lpszDevice,        // device name
      string lpszOutput,        // not used; should be NULL
     IntPtr lpInitData // optional printer data
      ); private void PerformCapture()
    {
    this.Visible = false;
    IntPtr dc1 = CreateDC("DISPLAY", null, null, (IntPtr)null);
    Graphics g1 = Graphics.FromHdc(dc1);
    MyImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
    Graphics g2 = Graphics.FromImage(MyImage);
    Visible = false;
        dc1 = g1.GetHdc();
    IntPtr dc2 = g2.GetHdc();
    BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc1, 0, 0, 13369376);
    g1.ReleaseHdc(dc1);
    g2.ReleaseHdc(dc2);
    MyImage.Save(@"c:\Captured.jpg", ImageFormat.Jpeg);
    Visible = true;
    MessageBox.Show("Finished Saving Image");
    this.Visible = true;
    this.SetBounds(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    SetupCropping();
    firstCrop = true;
    }