BitBlt 截图问题

windhuan windhuan 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
先上代码

IntPtr hdcSrc = IntPtr.Zero;
hdcSrc = User32.GetWindowDC(handle);
// create a device context we can copy to
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
// create a bitmap we can copy it to,
// using GetDeviceCaps to get the width/height
IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
// select the bitmap object
IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
// bitblt over
GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, x, y, GDI32.SRCCOPY);

// restore selection
GDI32.SelectObject(hdcDest, hOld);
// clean up
GDI32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
// get a .NET image object for it
Image img = Image.FromHbitmap(hBitmap);
// free up the Bitmap object
GDI32.DeleteObject(hBitmap);
((Bitmap)img).Save("1.bmp");
return (Bitmap)img;



问题描述,此段代码是截取指定DirextX窗口图片,自从更新了Win10 周年更新后无法工作,截取出来是黑的,之前都是好好的
但是如果把handle设置为GetDesktopWindow() ,可以截图 包括DirextX窗口内容,如何修改才能截取指定DirextX窗口图片
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
windhuan
C# 111,128 成员 642,536 内容