需要在X11中使用imLib2库拍摄快照

时间:2013-03-18 13:46:44

标签: linux x11 embedded-linux

我们需要在单击按钮时拍摄当前正在运行的应用程序窗口的快照。这应该在代码中自动完成。为此,我们使用了Imlib2库并使用以下api的imlib_create_image_from_drawable和imlib_copy_drawable_to_image。这是我们用于拍摄快照的代码,但它不起作用请提前感谢。

Imlib_Image buffer;
buffer = imlib_create_image_from_drawable(pixmap, 0, 0, glb.windowWidth, glb.windowHeight, 0); 
imlib_context_set_image(buffer);
imlib_copy_drawable_to_image(pixmap, 0, 0, glb.windowWidth, glb.windowHeight, 0, 0, 0);
imlib_context_set_image(buffer);
imlib_image_set_format("png");
imlib_save_image("screenshot");
imlib_free_image();

1 个答案:

答案 0 :(得分:2)

谢谢。我已经纠正了我的代码,我可以使用Imlib库获取正在运行的应用程序的快照。在上面我忘了设置drawable。这是更正的代码,它工作正常

Imlib_Image buffer;

buffer = imlib_create_image(glb.windowWidth, glb.windowHeight); 
imlib_context_set_image(buffer);
imlib_context_set_display(display);
imlib_context_set_visual(DefaultVisual(display, 0));
imlib_context_set_drawable(window);
imlib_copy_drawable_to_image(0, 0, 0, glb.windowWidth, glb.windowHeight, 0, 0, 1);
imlib_context_set_image(buffer);
imlib_image_set_format("png");
imlib_save_image("screenshot");
imlib_free_image();