如何显示一张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);
阅读(1311) | 评论(0) | 转发(0) |