需要刮擦分层窗口的帮助
我正在尝试抓取(拍摄屏幕截图)分层窗口,但它似乎无法正常工作。有些分层窗口工作正常,有些则不然。以下是我的做法:
IntPtr display_dc = GetDC(IntPtr.Zero);
IntPtr bitmap_dc = CreateCompatibleDC(display_dc);
IntPtr bitmap = CreateCompatibleBitmap(display_dc, rect.Width, rect.Height);
IntPtr null_bitmap = SelectObject(bitmap_dc, bitmap);
IntPtr window_dc = GetWindowDC(Handle);
BitBlt(bitmap_dc, 0, 0, rect.Width, rect.Height, window_dc, 0, 0,
TernaryRasterOperations.SRCCOPY | TernaryRasterOperations.SRCPAINT);
ReleaseDC(Handle, window_dc);
SelectObject(bitmap_dc, null_bitmap);
DeleteDC(bitmap_dc);
using (Bitmap temp = Bitmap.FromHbitmap(bitmap))
{
temp.Save(String.Format(@"C:\{0}_test.bmp", Handle.ToString("x")));
}
DeleteObject(bitmap);
ReleaseDC(IntPtr.Zero, display_dc);
问题是,当通过 UpdateLayeredWindow 更新分层窗口时,我为通过 SetLayeredWindowAttributes 创建的窗口获得了正确的图像,并获得了黑色位图。有人可以告诉我是否有一种方法可以通过 UpdateLayeredWindow win api 调用来抓取更新的分层窗口?
到目前为止,我的解决方法是拍摄整个屏幕的屏幕截图,然后从中复制窗口位图,问题是窗口应该始终位于顶部才能正常工作。
TIA
I'm trying to scrape (take a screen shot) a layered window and it doesn't seem work correctly. Some layered windows are working fine and some are not. Below is how I'm doing this:
IntPtr display_dc = GetDC(IntPtr.Zero);
IntPtr bitmap_dc = CreateCompatibleDC(display_dc);
IntPtr bitmap = CreateCompatibleBitmap(display_dc, rect.Width, rect.Height);
IntPtr null_bitmap = SelectObject(bitmap_dc, bitmap);
IntPtr window_dc = GetWindowDC(Handle);
BitBlt(bitmap_dc, 0, 0, rect.Width, rect.Height, window_dc, 0, 0,
TernaryRasterOperations.SRCCOPY | TernaryRasterOperations.SRCPAINT);
ReleaseDC(Handle, window_dc);
SelectObject(bitmap_dc, null_bitmap);
DeleteDC(bitmap_dc);
using (Bitmap temp = Bitmap.FromHbitmap(bitmap))
{
temp.Save(String.Format(@"C:\{0}_test.bmp", Handle.ToString("x")));
}
DeleteObject(bitmap);
ReleaseDC(IntPtr.Zero, display_dc);
The problem is that, I'm getting correct images for windows created via SetLayeredWindowAttributes and a black bitmap when layered window is updated via UpdateLayeredWindow. Can somebody tell me if there us a way to scrape a layered windows updated via UpdateLayeredWindow win api call?
Workaround I have so far is to take screen shot of the entire screen and then copy the window bitmap from it, the problem is that window should be always on top for this to work correctly.
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论