2013-06-05 33 views
1

我正在尋找一個程序在Linux中使用C或Cpp捕獲屏幕。有人可以幫助給出一個框架結構或程序什麼可以幫助我。在C或C++和Linux中的屏幕捕獲程序

感謝和問候, RC

+1

可能重複的[最快方法在Linux的屏幕捕獲(http://stackoverflow.com/questions/13479975/fastest-method-for- screen-capturing-on-linux) –

+0

閱讀libX11手冊:您可以抓取顯示並將其內容保存到文件中。 –

+0

從'xwd'來源獲取代碼:您只需要1-2頁的代碼! –

回答

3

How to capture screen with ffmpeg:

使用x11grab設備:

ffmpeg的-f x11grab -r 25 -s 1024×768 -i:0.0 + 100200 output.flv

這將從桌面抓取圖像,從左上角的 拐角開始(x = 100,y = 200),寬度和高度均爲1024x768。

如果您需要的音頻也可以使用ALSA這樣的:

ffmpeg的-f x11grab -r -s 25 1024x768的-i:0.0 + 100,200 -f ALSA -ac 2 -i 脈衝output.flv

所以,你可以簡單地將這個在capture.sh,並從你的代碼運行:

#include <cstdlib> 

int main(){ std::system("./capture.sh"); } 

如果你必須這樣做,而不調用外部工具,您可以使用libffmpeg directly.

+0

看起來不錯。我試圖使用外部庫,但無法找到一個完美的程序。有沒有任何示例程序使用第三方API來捕捉屏幕截圖? – Pferd

+0

It works http://stackoverflow.com/questions/15507788/making-a-screenshot-using-xlib-and-cairo-libs-fail – Pferd

0

開源「scrot」程序可能會滿足您的需求。

Licenses   BSD Original 
Operating Systems POSIX BSD Linux 
Implementation  C language 

得到scrot源代碼的here

scrot-0.8/src$ wc -l *.{c,h} 
    187 getopt1.c 
1043 getopt.c 
    57 imlib.c 
    632 main.c 
    264 options.c 
    31 debug.h 
    136 getopt.h 
    51 options.h 
    96 scrot.h 
    31 structs.h 
2528 total