还是关于bmp文件的问题,有些错误麻烦帮帮忙!!!
我写出了源码,不过就是有错误,自己也不知道怎么解决了...程序代码:
#include <CONIO.H> #include <STDLIB.H> #include <STDIO.H> #include <MATH.H> #include <string.h> #include <malloc.h> #include <string.h> typedef unsigned char BYTE; typedef unsigned short WROD; typedef unsigned long DWORD; //******文件头********** #include<pshpack2.h> //sizeof(BITMAPFILEHEADR)=14, otherwise sizeof(BITMAPFILEHEADER)=16 typedef struct tagBITMAPFILEHEADR { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; }BITMAPFILEHEADER; //******信息头******** #include<poppack.h> typedef struct tagBITMAPINFOHEADER { DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant; }BITMAPINFOHEADER; //************BMP图像RGB数据********** typedef struct tagRGBDATA { BYTE rgbBlue; BYTE rgbRed; BYTE rgbGreen; }RGBDATA; main() { RGBDATA *bmpdata=NULL; long width=128; long height=128; long datasize=widht*height; BITMAPFILEHEADER bmfHeader; BITMAPINFOHEADER bmiHeader; FILE *p,*fp; int i,j,k,x=0,y=0; char temp[128]; char dz[112][128]; fp=fopen("coki.txt","r"); if(!fp)//打开TXT文本 { printf("error!!!\n"); exit(0); } for(i=0;i<112;i++)//行循环;从TXT文本读取数据,存入点阵dz[][]中 { fscanf("%s",temp); for(y=0;y<128;y++)//列循环 { if(temp[y]=='_'||temp[y]=='X') dz[x][y]=temp[y]; if(temp[y]==',') dz[x][y]=dz[x][y-1];//读掉“,” } x++; } /***********创建BMP文件**************/ p=fopen("coki.bmp","wb+"); if(!p) { printf("error!!!\n"); exit(0); } //第二步:置文件头数据并写入BMP文件 bmfHeader.bfType=0x4d42; bmfHeader.bfSize=14+40+width*height*3; bmfHeader.bfReserved1=0; bmfHeader.bfReserved2=0; bmfHeader.bfoffBits=0x36; fwrite(&bmfHeader, sizeof(BITMAPFILEHEADER), 1, p); //第三步:置信息头数据并写入BMP文件 bmiHeader.biSize=40; bmiHeader.biWidth=width; bmiHeader.biHeight=height; bmiHeader.biPlanes=1; bmiHeader.biBitCount=24; bmiHeader.biCompress=0; bmiHeader.biSizeImage=width*height*3; bmiHeader.biXPeIsPerMeter=0; bmiHeader.biYPeIsPerMeter=0; bmiHeader.biCIrUsed=0; bmiHeader.biClrImprotant=0; fwrite(&bmiHeader, sizeof(BITMAPINFOHEADER), 1, p); //第四步:写入RGB数据 //申请一块内存,放入RGB数据 bmpdata=(RGBDATA* )malloc(width*height*3); if(!bmpdata) { printf("error!!!\n"); } /*//设置边框 for(i=0;i<height;i++) { if(i<8||i>120) { for(j=0;j<width;j++) dz1[i][j]='X'; } else { for(j=0;j<8;j++) dz1[i][j]='X'; for(j=120;j<128;j++) dz1[i][j]='X'; } }*/ for(i=0;i<height;i++) { for(j=0;j<width;j++) { k=(height-i-1)*width+j; if(temp[x][y]=='_') { bmpdata[k].rgbBule=255; bmpdata[k].rgbRed=255; bmpdata[k].rgbGreen=255; } if(temp[x][y]=='X') { bmpdata[k].rgbBlue=12; bmpdata[k].rgbRed=12; bmpdata[k].rgbGreen=12; } } } fwrite(bmpdata,sizeof(RGBDATA),datasize,p); printf("BMP文件成功生成\n"); free(bmpdata); fclose(fp); //fclose(p); }其中错误主要有:
程序代码:
G:\vc6\BMP\2-27\z.cpp(21) : error C2146: syntax error : missing ';' before identifier 'bfType' G:\vc6\BMP\2-27\z.cpp(21) : error C2501: 'WORD' : missing storage-class or type specifiers G:\vc6\BMP\2-27\z.cpp(21) : error C2501: 'bfType' : missing storage-class or type specifiers G:\vc6\BMP\2-27\z.cpp(23) : error C2146: syntax error : missing ';' before identifier 'bfReserved1'G:\vc6\BMP\2-27\z.cpp(100) : error C2039: 'bfType' : is not a member of 'tagBITMAPFILEHEADR' G:\vc6\BMP\2-27\z.cpp(20) : see declaration of 'tagBITMAPFILEHEADR' G:\vc6\BMP\2-27\z.cpp(102) : error C2039: 'bfReserved1' : is not a member of 'tagBITMAPFILEHEADR' G:\vc6\BMP\2-27\z.cpp(20) : see declaration of 'tagBITMAPFILEHEADR'谁能帮我看看...