最近需要完成一个从framebuffer中进行读取,然后将内存的东西保存为bmp图片格式,我的其他博客内容对framebuffer进行详细的讲解,以及bmp的格式进行详细的讲解。
之前从网上看到了一些保存bmp图片的代码,在本地执行都会出现问题,本人就进行了自己编写,可以指定文件的文件名和文件类型
也可以从github中获取源码:
直接看代码:https://github.com/Guazhen/Framebuffer_shot
#include <linux/fb.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <getopt.h>
#include <strings.h>
#include <unistd.h>
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef unsigned long LONG;
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} __attribute__((packed)) BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER
{
DWORD biSize; /*info header size in bytes*/
DWORD biWidth; /*widht of image*/
DWORD biHeight;/*height of image*/
WORD biPlanes;/*number of colour planes*/
WORD biBitCount;/*bits per