如何使用 Xlib 将一个窗口的内容复制到另一个窗口?
我想使用 Xlib 将现有窗口的内容复制到我自己的窗口。我尝试过 XCopyArea,但它拒绝在两个 Windows 之间复制。我也尝试过 XGetImage 和 XPutImage 但也失败了。
将窗口的图形内容复制到我自己的窗口的最佳方法是什么?
第二部分:
根据以下信息,我能够使 XCopyArea 和 XGetImage 正常工作。它不起作用的原因是源窗口和目标窗口的深度不同。我很惊讶地发现不同的 Windows 在我的桌面上有不同的深度。
但我在 XCopyArea 方面取得的成功仍然有限。如果我从某些 Windows(例如 Google Chrome)的顶部开始复制,它不会复制整个区域,只会复制标题栏。 XGetImage 在这些情况下工作得很好。关于为什么 XCopyArea 不会复制到某些 Windows 的标题栏之外的任何线索?
I want to copy the contents of an existing Window to my own Window using Xlib. I have tried XCopyArea and it refuses to copy between two Windows. I have also tried XGetImage and XPutImage and it's also failing.
What's the best way to copy the graphics contents of a Window to my own?
Part II:
Based on information below, I was able to get XCopyArea and XGetImage to work. The reason it wasn't working was difference in depth of source and destination Window. I was surprised to learn that different Windows have different depth on my desktop.
But I still have limited success with XCopyArea. If I start copying from the top of certain Windows, like Google Chrome, it doesn't copy the full area, just the title bar. XGetImage works fine in those cases. Any clue on why XCopyArea won't copy beyond the title bar of some Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XCopyArea 应该没问题。
请注意,这只会复制到目标的前台 - 也许它正在被绘制然后被删除?
没有代码我可以推测:
如果失败,您是否检查过窗口是否确实具有相同的根和深度?
还要确保您检查了 X Window 坐标系。也许尝试复制,使副本的一角位于目的地的中心,看看是否可以获得任何东西。
您通常需要某种方式在目标窗口中处理 Expose 事件,以便可以进行刷新。
我建议创建一个 Pixmap 作为中间体。 Pixmap 和 Window 都是可绘制的。
使用 XCopyArea 复制到 Pixmap 中。
然后使用 XSetWindowBackgroundPixmap 实际渲染图像。设置背景意味着您可以忽略处理 Expose 事件以重绘图像的任何需要。
XCopyArea should be fine.
Note that this will only copy into the foreground of the destination - maybe it is being drawn then erased?
Without code I can speculate:
If it is failing, have you checked that the windows definitely have the same root and depth?
Also make sure you review the X Window coordinate system. Maybe try copying so that the corner of your Copy is in the centre of the Destination to see if you can get anything.
You normally want some way of handling Expose events in the destination window so you can do a refresh.
I'd recommend creating a Pixmap as an intermediate. Both Pixmap and Window are Drawable.
Use XCopyArea to copy into the Pixmap.
Then use XSetWindowBackgroundPixmap to actually render the image. Setting the background means you can then ignore any need for handling Expose events to redraw the image.