I';我正试图读取位图文件 我试图用C++来读取一个灰度位图文件。以下是获取有关该文件的所有信息的代码,如上的wikipeadia页面所示: intmain(){ 文件*fptr; 字符串文件名; cout
我真的不会担心。你的I';我正试图读取位图文件 我试图用C++来读取一个灰度位图文件。以下是获取有关该文件的所有信息的代码,如上的wikipeadia页面所示: intmain(){ 文件*fptr; 字符串文件名; cout,c++,bitmap,C++,Bitmap,我真的不会担心。你的1078+512*512=263222计算是正确的。在我通过谷歌(例如,或德国维基百科条目)找到的各种链接上,它说标题中的bfSize条目“不可靠” [编辑:nevermind]如何获得“文件大小”?如何获得偏移量?请尝试创建一个新的文件并向我们展示(代码显示超过1000张图片).您读取文件的代码是什么?我们如何知道您是否使用标准的Cfseek和fread函数?您需要更具体一些。现在您所问的是不可能的,因为我们不知道您是如何获得文件信息的,尤其是大小。 int main()
1078+512*512=263222
计算是正确的。在我通过谷歌(例如,或德国维基百科条目)找到的各种链接上,它说标题中的bfSize
条目“不可靠”
[编辑:nevermind]如何获得“文件大小”?如何获得偏移量?请尝试创建一个新的文件并向我们展示(代码显示超过1000张图片).您读取文件的代码是什么?我们如何知道您是否使用标准的C
fseek
和fread
函数?您需要更具体一些。现在您所问的是不可能的,因为我们不知道您是如何获得文件信息的,尤其是大小。
int main() {
FILE *fptr;
string fileName;
cout<<"Please provide the name of the file: "<<endl;
cin>>fileName;
fileName = "Test Images/"+fileName+".bmp";
fptr = fopen(fileName.c_str(), "rb");
cout<<"FileName : "<<fileName<<endl;
if(fptr == NULL){
cout<<"File Not found"<<endl;
getch();
return -1;
}
unsigned char total[54];
fread(total, sizeof(unsigned char), 54, fptr);
cout<<endl;
cout<<"Type: "<< *(char*)&total[0x00]<<*(char*)&total[0x01] <<endl;
cout<<"size: "<< *(int*)&total[0x02]<<endl;
cout<<"offset: "<< *(int*)&total[0x0A]<<endl;
cout<<"Info header size: "<< *(int*)&total[0x0E]<<endl;
cout<<"Bitmap width: "<< *(int*)&total[0x12]<<endl;
cout<<"Bimap height "<< *(int*)&total[0x16]<<endl;
cout<<"Color planes: "<< *(int*)&total[0x1A]<<endl;
cout<<"BPP: "<< *(short int*)&total[0x1C]<<endl;
cout<<"Compression Method "<< *(int*)&total[0x1E]<<endl;
cout<<"Raw bmp data size: "<< *(int*)&total[0x22]<<endl;
cout<<"Horizontal Resolution: "<< *(int*)&total[0x26]<<endl;
cout<<"Vertical Resolution: "<< *(int*)&total[0x2A]<<endl;
cout<<"No of Color: "<< *(int*)&total[0x2E]<<endl;
cout<<"No of imp colors: "<< *(int*)&total[0x32]<<endl;
fclose(fptr);
getch();
return 0;
}