BitBlt screen capture not working on Windows 10

前端 未结 1 835
我在风中等你
我在风中等你 2020-12-14 07:59

I\'m using this code to capture a process window in the background:

IntPtr = Process.GetProcessByName(\"memu\")[0].MainWindowHandle;
RECT rc;
GetClientRect(h         


        
1条回答
  •  温柔的废话
    2020-12-14 08:14

    Hopefully this will solve the problem. There is a method for capturing the screen that is built in to the .net framework that may work. Not sure if it will capture DirectX content, but it may be worth a try.

    Please note that this solution captures the current screen, but you will probably be able to modify it to capture only the area you are interested in.

    I found this solution here: https://www.c-sharpcorner.com/UploadFile/2d2d83/how-to-capture-a-screen-using-C-Sharp/

    private void CaptureMyScreen()
    {
          try
          {
               //Creating a new Bitmap object
              Bitmap captureBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);
    
             //Bitmap captureBitmap = new Bitmap(int width, int height, PixelFormat);
             //Creating a Rectangle object which will  
             //capture our Current Screen
             Rectangle captureRectangle = Screen.AllScreens[0].Bounds;
    
             //Creating a New Graphics Object
             Graphics captureGraphics = Graphics.FromImage(captureBitmap);
    
            //Copying Image from The Screen
            captureGraphics.CopyFromScreen(captureRectangle.Left,captureRectangle.Top,0,0,captureRectangle.Size);
    
            //Saving the Image File (I am here Saving it in My E drive).
            captureBitmap.Save(@"E:\Capture.jpg",ImageFormat.Jpeg);
    
            //Displaying the Successfull Result
    
            MessageBox.Show("Screen Captured");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    

    0 讨论(0)
提交回复
热议问题