linux截屏程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/czhzasui/article/details/82356115

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

//
// Created by czh on 18-9-3.
//
#include <unistd.h>
#include <unistd.h>
#include <opencv2/opencv.hpp>
#include <vector>

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;
}

猜你喜欢

转载自blog.csdn.net/czhzasui/article/details/82356115