简体   繁体   English

如何使用Xlib将一个窗口的内容复制到另一个窗口?

[英]How can I copy contents of one window to another using Xlib?

I want to copy the contents of an existing Window to my own Window using Xlib. 我想使用Xlib将现有Window的内容复制到我自己的Window。 I have tried XCopyArea and it refuses to copy between two Windows. 我尝试过XCopyArea,它拒绝在两个Windows之间复制。 I have also tried XGetImage and XPutImage and it's also failing. 我也尝试过XGetImage和XPutImage,它也失败了。

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. 根据以下信息,我能够使XCopyArea和XGetImage工作。 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. 我惊讶地发现不同的Windows在我的桌面上有不同的深度。

But I still have limited success with XCopyArea. 但是我对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. 如果我从某些 Windows的顶部开始复制,例如谷歌浏览器,它不会复制整个区域,只复制标题栏。 XGetImage works fine in those cases. 在这些情况下,XGetImage工作正常。 Any clue on why XCopyArea won't copy beyond the title bar of some Windows? 有关为什么XCopyArea不会复制到某些 Windows的标题栏之外的任何线索?

XCopyArea should be fine. XCopyArea应该没问题。 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. 还要确保查看X Window坐标系。 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. 您通常需要某种方法来处理目标窗口中的Expose事件,以便您可以进行刷新。

I'd recommend creating a Pixmap as an intermediate. 我建议创建一个Pixmap作为中间件。 Both Pixmap and Window are Drawable. Pixmap和Window都是可绘制的。 Use XCopyArea to copy into the Pixmap. 使用XCopyArea复制到Pixmap中。 Then use XSetWindowBackgroundPixmap to actually render the image. 然后使用XSetWindowBackgroundPixmap实际渲染图像。 Setting the background means you can then ignore any need for handling Expose events to redraw the image. 设置背景意味着您可以忽略处理Expose事件以重绘图像的任何需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM