JOGL小程序Win7下截屏
我正在尝试截取在 a 中运行的小程序的屏幕截图 浏览器。该小程序使用 JOGL (OpenGL for Java) 来显示 3D 模型。 (1) 屏幕截图始终显示为黑色或白色。 当前的解决方案使用通常的 GDI 调用。小程序的屏幕截图不 运行 OpenGL 没问题。
可以在此处找到 JOGL 应用程序的一些示例 https://jogl-demos.dev.java.net / (2)我想要实现的另一件事是获取可滚动区域 屏幕截图内也是如此。
我在互联网上找到了这段代码,除了 2 之外,它工作正常 上面提到的问题。
import win32gui as wg
import win32ui as wu
import win32con
def copyBitMap(hWnd, fname):
wg.SetForegroundWindow(hWnd)
cWnd = wu.CreateWindowFromHandle(hWnd)
rect = cWnd.GetClientRect()
(x,y) = (rect[2] - rect[0], rect[3] - rect[1])
hsrccDc = wg.GetDC(hWnd)
hdestcDc = wg.CreateCompatibleDC(hsrccDc)
hdestcBm = wg.CreateCompatibleBitmap(hsrccDc, x, y)
wg.SelectObject(hdestcDc, hdestcBm.handle)
wg.BitBlt(hdestcDc, 0, 0, x, y, hsrccDc, rect[0], rect[1], win32con.SRCCOPY)
destcDc = wu.CreateDCFromHandle(hdestcDc)
bmp = wu.CreateBitmapFromHandle(hdestcBm.handle)
bmp.SaveBitmapFile(destcDc, fname)
I'm trying to take a screen shot of an applet running inside a
browser. The applet is using JOGL (OpenGL for Java) to display 3D
models. (1) The screen shots always come out either black or white.The
current solution uses the usual GDI calls. Screen shots of applets not
running OpenGL are fine.
A few examples of JOGL apps can be found here https://jogl-demos.dev.java.net/
(2) Another thing I'm trying to achieve is to get the scrollable area
inside the screen shot as well.
I found this code on the internet which works fine except for the 2
issues mentioned above.
import win32gui as wg
import win32ui as wu
import win32con
def copyBitMap(hWnd, fname):
wg.SetForegroundWindow(hWnd)
cWnd = wu.CreateWindowFromHandle(hWnd)
rect = cWnd.GetClientRect()
(x,y) = (rect[2] - rect[0], rect[3] - rect[1])
hsrccDc = wg.GetDC(hWnd)
hdestcDc = wg.CreateCompatibleDC(hsrccDc)
hdestcBm = wg.CreateCompatibleBitmap(hsrccDc, x, y)
wg.SelectObject(hdestcDc, hdestcBm.handle)
wg.BitBlt(hdestcDc, 0, 0, x, y, hsrccDc, rect[0], rect[1], win32con.SRCCOPY)
destcDc = wu.CreateDCFromHandle(hdestcDc)
bmp = wu.CreateBitmapFromHandle(hdestcBm.handle)
bmp.SaveBitmapFile(destcDc, fname)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除非你想自动化它,否则我只会使用 Firefox 扩展。其中有许多是从搜索“screenshot” 可以截取整个浏览器页面(包括可滚动区域)的屏幕截图:
但是,我很抱歉,我对 Python 的了解不够,无法调试您的如果您确实尝试以编程方式执行此操作,则存在特定问题。
Unless you are trying to automate it, I would just use a Firefox extension for this. There are a number of them returned from a search for "screenshot" that can take a screenshot of the entire browser page including the scrollable area:
However, I apologize, I don't know enough about Python to debug your specific issue if you are indeed trying to do it programmatically.
一种方法是在拍摄屏幕截图之前禁用 dwm(桌面窗口管理器)合成,但这会导致整个屏幕在启用/禁用时闪烁。
Here is one way to do it by disabling dwm (Desktop Window Manager) composition before taking the screen shot, but this causes the whole screen to blink whenever its enabled/disabled.
在某些情况下,抓取 OpenGL 窗口可能非常困难,因为 OpenGL 是由 GPU 直接渲染到其帧缓冲区中的。这同样适用于 DirectX 窗口和视频覆盖窗口。
Grabbing an OpenGL window may be quite hard in some cases, since the OpenGL is being rendered by the GPU directly into its frame buffer. The same applies to DirectX windows and Video overlay windows.
为什么不使用JOGL的Screenshot类?
com.jogamp.opengl.util.awt.JOGL 2.0 beta 中的屏幕截图
Why not using the Screenshot class of JOGL??
com.jogamp.opengl.util.awt.Screenshot in JOGL 2.0 beta