linux截屏程序

利用opencv从frambuffer读取桌面图片,实现截屏,并保存为png32格式图片.

//
// Created by czh on 18-9-3.
//
#include 
#include 
#include 
#include 

int main()
{
    unsigned char buf[1280 * 480 * 4];
    int fb;

    fb = open("/dev/fb0", O_RDONLY);
    if(fb < 0)
        exit(1);
    printf("reading screen...\n");
    read(fb, buf, 1280 * 480 * 4);
    close(fb);
    printf("saving screen...\n");
    std::vector<int> params;
    params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    params.push_back(0);
    cv::Mat BGRA(480, 1280, CV_8UC4);
    BGRA.data = buf;

    imwrite("./screen.png", BGRA, params);

    return 0;
}

你可能感兴趣的:(OpenCV)