码迷,mamicode.com
首页 > 其他好文 > 详细

阶段小项目2:显示bin格式图片

时间:2016-02-14 20:59:51      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<error.h>
#include<errno.h>
#include<unistd.h>
#include<strings.h>
#include<stdbool.h>

#include<sys/stat.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<fcntl.h>
#include<sys/mman.h>
int main(int argc,char **argv)
{
if(argc != 2)
{
fprintf(stderr,"Usage:%s <dir>",argv[0],strerror(errno));
}
int fd = open("/dev/fb0",O_RDWR);
if(fd == -1)
{
perror("open() failed!");
exit(0);
}

int fd0 = open(argv[1],O_RDONLY);//注意bin文件是一个只读文件否则无法打开
if(fd0 == -1)
{
perror("open fd0 failed !");
exit(0);
}
char *p = mmap(NULL,800*480*4,PROT_READ | PROT_WRITE,MAP_SHARED,fd,0);

int nread = 800*480*4;
int n;
while(nread > 0)
{
n = read(fd0,p,nread);//可以直接读到映射内存中,中间不需要一个buff.
nread -= n;   //这里不能确定是否能一次全部读取到。
p += n; //注意指针的移动。
}
return 0;
}

阶段小项目2:显示bin格式图片

标签:

原文地址:http://www.cnblogs.com/defen/p/5189514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!