高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-1-6
|
楼主 |
发表于 2015-3-12 14:28:03
|
显示全部楼层
我直接在资料里拷过来的。哪里有问题?
void Lcd_show_bmp(unsigned short int x, unsigned short int y,unsigned char *pic_name)
{
int i, j, k;
int width, height, l_width;
BYTE red,green,blue;
BITMAPFILEHEADER bitHead;
BITMAPINFOHEADER bitInfoHead;
WORD fileType;
unsigned int read_num;
unsigned char tmp_name[20];
sprintf((char*)tmp_name,"0:%s",pic_name);
f_mount(0, &bmpfs[0]);
BMP_DEBUG_PRINTF("file mount ok \r\n");
bmpres = f_open( &bmpfsrc , (char *)tmp_name, FA_OPEN_EXISTING | FA_READ);
Set_direction(0);
if(bmpres == FR_OK)
{
BMP_DEBUG_PRINTF("Open file success\r\n");
//读取位图文件头信息
f_read(&bmpfsrc,&fileType,sizeof(WORD),&read_num);
if(fileType != 0x4d42)
{
BMP_DEBUG_PRINTF("file is not .bmp file!\r\n");
return;
}
else
{
BMP_DEBUG_PRINTF("Ok this is .bmp file\r\n");
}
f_read(&bmpfsrc,&bitHead,sizeof(tagBITMAPFILEHEADER),&read_num);
showBmpHead(&bitHead);
BMP_DEBUG_PRINTF("\r\n");
//读取位图信息头信息
f_read(&bmpfsrc,&bitInfoHead,sizeof(BITMAPINFOHEADER),&read_num);
showBmpInforHead(&bitInfoHead);
BMP_DEBUG_PRINTF("\r\n");
}
else
{
BMP_DEBUG_PRINTF("file open fail!\r\n");
return;
}
width = bitInfoHead.biWidth;
height = bitInfoHead.biHeight;
l_width = WIDTHBYTES(width* bitInfoHead.biBitCount); //计算位图的实际宽度并确保它为32的倍数
if(l_width>960)
{
BMP_DEBUG_PRINTF("\nSORRY, PIC IS TOO BIG (<=320)\n");
return;
}
if(bitInfoHead.biBitCount>=24)
{
bmp_lcd(x,240-y-height,width, height); //LCD参数相关设置
for(i=0;i<height+1; i++)
{
for(j=0; j<l_width; j++) //将一行数据全部读入
{
f_read(&bmpfsrc,pColorData+j,1,&read_num);
}
for(j=0;j<width;j++) //一行有效信息
{
k = j*3; //一行中第K个像素的起点
red = pColorData[k+2];
green = pColorData[k+1];
blue = pColorData[k];
LCD_WR_Data(RGB24TORGB16(red,green,blue)); //写入LCD-GRAM
}
}
bmp_lcd_reset(); //lcd扫描方向复原
}
else
{
BMP_DEBUG_PRINTF("SORRY, THIS PIC IS NOT A 24BITS REAL COLOR");
return ;
}
f_close(&bmpfsrc);
}
|
|