#include <windows.h>//definition structure containing the relevant BMP format#include <stdio.h>#include<stdlib.h>intBmpwidth;//bmp picture Width (pixels)intBmpheight;//bmp picture Height (pixels)rgbquad* pcolortable;//palette Array (true Color not required)intbiBitCount;//bytes per pixel/************************************************************** Name: read_bmp* function: Read BMP image, return the read out of the 16 binary array * Entry parameter: Bmpfilename:bmp picture name * Export parameter: no **************************************************************/unsignedChar* Read_bmp (Const Char*bmpfilename) {unsignedChar* PBMPBUF;//Storage Buffersfile* fp = fopen (Bmpfilename,"RB");//Binary system Open if(fp = =NULL) {printf ("Can not open the This file"); return 0; } fseek (FP,sizeof(Bitmapfileheader),0);//Skip BMP HeadBitmapinfoheader Infoheader; Fread (&infoheader,sizeof(Bitmapinfoheader),1, FP);//read BMP picture informationBmpwidth =Infoheader.biwidth; Bmpheight=Infoheader.biheight; biBitCount=Infoheader.bibitcount; intLine_byte = (bmpwidth*bibitcount/8+3)/4*4;//the number of bytes per row if(biBitCount = =8) {pcolortable=Newrgbquad[ the]; Fread (pcolortable,sizeof(Rgbquad), the, FP); } pbmpbuf=NewUnsignedChar[Line_byte*bmpheight];//Open Storage AreaFread (Pbmpbuf,1, line_byte*BMPHEIGHT,FP); Fclose (FP); //Close File returnpbmpbuf;}/************************************************************** Name: main* function: Test function * Entry parameter: None * Export parameter: no *************** ***********************************************/ intMain () {unsignedChar* Buffer=read_bmp ("1.bmp");//Read BMP picturesfile* fp = fopen ("Test.txt","WB"); Fwrite (Buffer,1, (bmpwidth*bibitcount/8+3)/4*4*BMPHEIGHT,FP);//writes the read-out picture data to Test.txt return 0;}
The 16 binary data that is stored in the text file is garbled and needs to be read with the 16 binary editing tool, and the default BMP picture reads the book order from the bottom left corner, so when the display on the TFT, you need to pay attention to start scanning from the lower left corner, or first convert the data to the upper left corner to start the order.
C language Read BMP picture