【发布时间】:2021-06-16 23:26:25
【问题描述】:
我需要将我的应用程序放在全屏视频上并将其捕获以放入我的 python tkinter 应用程序中的“画中画”帧中。我已经查看了常见的嫌疑人(ImageGrab、mss 等),但它们似乎都只是抓取了监视器上可见的内容。似乎没有人能够抓住一个不可见的窗口。
我在 Stack Overflow 上发现了这个看起来很有希望的 C 程序:
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/X.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xrender.h>
int
main ()
{
Display *display = XOpenDisplay (NULL);
XID xid = 90177543; // xdotool search --name "World of Warcraft" | head -1
// Check if Composite extension is enabled
int event_base_return;
int error_base_return;
if (XCompositeQueryExtension (display, &event_base_return, &error_base_return))
printf ("COMPOSITE IS ENABLED!\n");
// Requests the X server to direct the hierarchy starting at window to off-screen storage
XCompositeRedirectWindow (display, xid, CompositeRedirectAutomatic);
// Preventing the backing pixmap from being freed when the window is hidden/destroyed
// If you want the window contents to still be available after the window has been destroyed,
// or after the window has been resized (but not yet redrawn), you can increment the backing
// pixmaps ref count to prevent it from being deallocated.
Pixmap pixmap = XCompositeNameWindowPixmap (display, xid);
// Get window attributes
XWindowAttributes attr;
Status s = XGetWindowAttributes (display, xid, &attr);
if (s == 0)
printf ("Fail to get window attributes!\n");
// Extract the data
XRenderPictFormat *format = XRenderFindVisualFormat (display, attr.visual);
int width = attr.width;
int height = attr.height;
int depth = attr.depth;
// What we need to do now is to create an XRender Picture for the window,
// which we'll need to draw it with the Render extension.
// A picture is a basically a handle to a server side struct with some
// additional information about a drawable (in this case a window),
// such as its format, which clipping region should be used when
// drawing it (if any), whether it should be tiled etc.
XRenderPictureAttributes pa;
pa.subwindow_mode = IncludeInferiors;
Picture picture = XRenderCreatePicture (display, xid, format, CPSubwindowMode, &pa);
// We now have all the information we need in order to be able to draw the window
// using the Xrender extension, and we've created and prepared a source picture
// for the window for this purpose.
// The Xrender function we'll use to draw the window is XRenderComposite().
//XRenderComposite (display, PictOpSrc, picture, None, ???destination???, 0,0, 0,0, 0,0, width, height);
XFreePixmap (display, pixmap);
XCompositeUnredirectWindow (display, xid, CompositeRedirectAutomatic);
return 0;
}
现在真正的问题...
我的问题是这部分:
#include <X11/Xlib.h>
#include <X11/X.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xrender.h>
所有这些文件都存在于/usr/include/X11 下,<X11/extensions/Xcomposite.h> 除外。我在哪里可以找到它?
Ubuntu 16.04 LTS (ESM),内核 4.14.216-0414216-generic。忙着学习新东西要打破,嗯,错误,升级到新版本。
FWIW 这是一个已经在运行的音乐播放器应用程序,单击按钮可降低电视音量并恢复音乐。我只是增强它以移动到电视上,拍摄全屏视频并将其放入专辑插图通常旋转的 tkinter 框架中。计时器完成后,电视恢复播放,音乐播放器移回它来自的其他显示器。因此,我认为我找到的这个 C 程序是唯一的解决方案,但我欢迎罐装解决方案。
【问题讨论】:
-
你不想运行 vnc 吗?
with the exception of <X11/extensions/Xcomposite.h>. Where might I find it?在某些包中。你有 ubuntu - 你在你的包管理器中搜索过这个文件吗? -
@KamilCuk 我已经安装了
libxcomposite1/xenial,now。我需要安装libxcomposite-dev/xenial吗? -
@KamilCuk 我不知道要不要跑
vnc???一年前有人告诉我运行pycharm而不是gedit,我上个月就这样做了,我爱死它了。我仍然在发现功能的冰山一角。现在我想知道是否有“C”-Charm,因为今晚的项目我又回到了gedit。有很多东西要学。今天我正在检查 Kotlin,以便让我的音乐播放器在 Google Automotive 汽车头罩上运行。
标签: c linux screenshot x11