framebuffer 保存png, bmp图片

   遇到一个需求,在读取/dev/fb0的原始数据并保存为bmp,png图片,并通过命令行格式进行保存.

   写的不好,大家可以指点出来,一起讨论.

  也将代码上传到github上了,地址:

https://github.com/Guazhen/Framebuffer_shot/blob/master/framework_shot.c

  root@imx6qsabresd:~# ./imx6_shot -h     
  usage: ./imx6_shot [-hpb] [FILENAME]
  imx6 [option]...
  -p|--png                Save the file as a png.
  -b|--bmp                Save the file as a bmp
  -h|--help               help information.
  If FILENAME ends with .png it will be saved as a png.
  If FILENAME ends with .bmp it will be saved as a bmp.
  If FILENAME is not given, the default will be saved as a png.

实现代码如下:

#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>


#include <stdlib.h>
#include <sys/vt.h>
#include <png.h>
#include <zlib.h>


static int Blue = 0;
static int Green = 1;
static int Red = 2;
static int Alpha = 3;


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 pixel*/
	DWORD biCompression;/*compression type*/
	DWORD biSizeImage;/*image size meter*/
	DWORD biXPelsPerMeter;/*pixels per meter*/
	DWORD biYPelsPerMeter;/*pexels per meter*/
	DWORD biClrUsed;/*number of colour*/
	DWORD biClrImportant;/*important colour*/
} __attribute__((packed)) BITMAPINFOHEADER;

int png_file;
int bmp
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值