zoukankan      html  css  js  c++  java
  • 阶段小项目2:显示bin格式图片

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

  • 相关阅读:
    Ansible中文权威指南学习
    gitlab
    Python-Day01-task
    Python-Day01
    CentOs6.7 python2.6升级到2.7.11
    网站访问慢排查方法及解决方案
    LAMP环境下zabbix安装配置
    监控知识点概述
    Java抽象类、接口和内部类
    Java 访问控制
  • 原文地址:https://www.cnblogs.com/defen/p/5189514.html
Copyright © 2011-2022 走看看