BitBlt屏幕截图在Windows 10上不起作用 [英] BitBlt screen capture not working on Windows 10

查看:613
本文介绍了BitBlt屏幕截图在Windows 10上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码在后台捕获进程窗口:

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

IntPtr = Process.GetProcessByName("memu")[0].MainWindowHandle;
RECT rc;
GetClientRect(hwnd, out rc);

IntPtr hdcFrom = GetDC(hwnd);
IntPtr hdcTo = CreateCompatibleDC(hdcFrom);

int Width = rc.right;
int Height = rc.bottom;

Bitmap bmp = null;

IntPtr hBitmap = CreateCompatibleBitmap(hdcFrom, Width, Height);
if (hBitmap != IntPtr.Zero) {
   IntPtr hLocalBitmap = SelectObject(hdcTo, hBitmap);

   BitBlt(hdcTo, 0, 0, Width, Height, hdcFrom, 0, 0, CopyPixelOperation.SourceCopy);
   SelectObject(hdcTo, hLocalBitmap);

   DeleteDC(hdcTo);
   ReleaseDC(hwnd, hdcFrom);

   bmp = Image.FromHbitmap(hBitmap);
   DeleteObject(hBitmap);
   return bmp;
}

此代码捕获了一个名为MEmu的Android仿真器,它使用DirectX进行渲染内容。但是此代码在Windows 10更新到版本16299(之前可以正常工作)后停止工作,但仍在启用Aero模式的Windows 7上运行。

This code is capture an Android emulator called MEmu, it is using DirectX to render the content. But this code stopped to work after Windows 10 updated to version 16299 (it was working normally before), it still working on Windows 7 with Aero mode enabled.

当我使用在Windows 10 Pro v16299.X中,此方法仅返回白色图像,或者返回模拟器的加载屏幕,而不是运行内容。在Windows 7上,如果我删除了Aero模式,它将起到相同的作用,捕获加载屏幕,因此看起来在新的Windows 10专业版更新中透明性的工作方式有所改变。

When I use this method in the Windows 10 Pro v16299.X it simply return a white image or it returns the emulator "loading screen", not the running content. On Windows 7, if I remove the Aero mode it will act the same, capturing the "loading screen", so looks like somehow the way the transparency works in the new windows 10 pro update changed.

我已经尝试了所有方法,尝试安装了一些模块以强制Aero Mode在Windows 10上运行,尝试了PrintWindow在后台捕获屏幕,但是还是一样。

I've tried everything, tried install some modules to force Aero Mode to work on Windows 10, tried PrintWindow to capture the screen in the background, but still the same.

有什么想法吗?还是可能的解决方案?还是在最后一个Windows 10 Pro版本中有什么更改可能会破坏该代码?

Any ideas what could be happening? Or a possible solution? Or what changed in this last Windows 10 Pro version that could break that code?

谢谢!

推荐答案

希望这可以解决问题。有一种捕获屏幕的方法,该屏幕内置在.net框架中可能有效。不确定是否可以捕获DirectX内容,但是值得一试。

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.

我在这里找到了此解决方案:> https://www.c-sharpcorner.com/UploadFile/2d2d83/how-to-capture-a -screen-using-C-Sharp /

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);
    }
}

这篇关于BitBlt屏幕截图在Windows 10上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆