Chinaunix首页 | 论坛 | 博客
  • 博客访问: 936413
  • 博文数量: 192
  • 博客积分: 3070
  • 博客等级: 中校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-27 23:44
个人简介

Start Linux Leave Linux a while Back to Linux

文章分类

全部博文(192)

文章存档

2023年(18)

2022年(11)

2021年(8)

2020年(14)

2019年(7)

2018年(13)

2017年(16)

2016年(4)

2012年(2)

2011年(13)

2010年(26)

2009年(13)

2008年(27)

2007年(20)

我的朋友

分类: LINUX

2009-04-29 22:59:06

如何显示一张BMP的图片到 EINK中.
之前显示BMP图片总是倒过来的,显示效果也不好,后果发现 BMP图片的数据是:
开头 118byte 是图片的信息,包括图片的大小,像素等等.
118Byte 之后就是图片的数据,图片的数据头和尾是对调的,所以顺序发送数据到 EPD上显示的图片是不正常的.
下面如何显示BMP图片部分的代码:
 
   FILE bmpfd;
   unsigned char *addr, *buf, tmp;
   int width, h, i;
 
   if (GetImageHeader (file, &ImageHeader))
   {
     printf("width: %d, height: %d\n", ImageHeader.Width ,ImageHeader.Height);
   }
 
   width = ImageHeader.Width;
   h = ImageHeader.Height;
 
 
   bmpfd = fopen(file,"r+");
   if(!bmpfd)
   {
     fclose(bmpfd); 
     printf("open %s file fail\n",file);
     return -1; 
   }  
 
   BytesPerRow  = (((((width - 1) / 2) / 4) + 1) * 4);//use w
   count = h * BytesPerRow;
   addr = (unsigned char *)malloc(sizeof(unsigned char)*count);
   buf = (unsigned char *)malloc(sizeof(unsigned char)*count);
   if(!addr){
     printf("assign memery error \n");
     return -1; 
   }
   memset(addr,0x00,count/2);
   fseek(bmpfd,118,SEEK_SET);
  
   int count = fread(addr,1,count,bmpfd);
   for(i=0;i
   {
      tmp = *(addr + i);
      *(addr + i) = ((tmp<<4)&0xf0) | ((tmp>>4)&0x0f);
   }
 
   start = addr + (count - BytesPerRow);
  
   // change data
   for(i=0;i
       *(buf + i) = start[i];
   }
  
  
   wrBsDataMain((unsigned char*)buf,BytesPerRow,h,width); 
 
 
 
 
 
 
阅读(1268) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~