我把bmp文件放到U盤(pán)里 讀出來(lái)的數(shù)據(jù)在串口打印出來(lái)的數(shù)據(jù)是WINHEX軟件打開(kāi)的bmp數(shù)據(jù),但是在解碼FILE_DATA_BUF緩沖區(qū)的文件時(shí) 總是空的!代碼如下: //bmp文件頭 struct BitMapFileHead{ UINT16 bfType; UINT32 bfSize; UINT16 bfReserved1; UINT16 bfReserved2; UINT32 bfoffBits; }MybmfHead; //bmp信息頭 struct BitMapInfoHeader{ UINT16 bfType; UINT32 biSize; UINT32 biWidth; UINT32 biHeight; UINT16 biPlanes; UINT16 biBitCount; UINT32 biCompress; UINT32 biSizeImage; UINT32 biXPeIsPerMeter;//水平分辨率 UINT32 biYPeIsPerMeter;//垂直分辨率 UINT32 biClrUsed; UINT32 biClrImportant; }MybmiHead; void From_Bmp2_Array(UINT8X *BMP_BUFFER,UINT8 data *ARRAY ) { // BitMapFileHead // BitMapInfoHeader MybmiHead; MybmfHead.bfType=((*(BMP_BUFFER+1))<<8)|(*(BMP_BUFFER+0)); MybmiHead.biWidth=((*(BMP_BUFFER+18))>>24) |((*(BMP_BUFFER+19))>>16) | ((*(BMP_BUFFER+20))>>8) | (*(BMP_BUFFER+21)); MybmiHead.biHeight=((*(BMP_BUFFER+22))>>24) | ((*(BMP_BUFFER+23))>>16) | ((*(BMP_BUFFER+20))>>8) | (*(BMP_BUFFER+24)); MybmiHead.biBitCount=((*(BMP_BUFFER+29))<<8)|(*(BMP_BUFFER+28)); MybmiHead.biCompress=((*(BMP_BUFFER+30))>>24) | ((*(BMP_BUFFER+31))>>16) | ((*(BMP_BUFFER+32))>>8) | (*(BMP_BUFFER+33)); if(MybmfHead.bfType==0x4D42) { if(MybmiHead.biBitCount==0x18) { UINT8 i; if(MybmiHead.biCompress==0) { for(i=54;i { *(ARRAY++) = *(BMP_BUFFER+i); } } else{ printf("It is not a uncompressed bmp file\n"); } } else{ printf("It is not a 24bit bmp file\n"); } } else{ printf("It is not bmp file\n"); } // printf("%c",ARRAY); } i = CH375FileClose( ); /* 關(guān)閉文件 */ mStopIfError( i );
i = FILE_DATA_BUF[100]; FILE_DATA_BUF[100] = 0; /* 置字符串結(jié)束標(biāo)志,最多顯示100個(gè)字符 */ // printf( "Line 1: %s\n", FILE_DATA_BUF ); FILE_DATA_BUF[100] = i; /* 恢復(fù)原字符 */ From_Bmp2_Array(FILE_DATA_BUF,Array );
for ( count=0; count < sizeof(Array); count ++ ) { /* 將文件中的小寫(xiě)字符轉(zhuǎn)換為大寫(xiě) */ c = Array[count]; printf("%c",c); //把從U盤(pán)讀到的數(shù)據(jù)在串口上打印出來(lái)。 if ( c >= 'a' && c <= 'z' ) Array[count] = c - ( 'a' - 'A' ); }