简体   繁体   中英

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. 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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