我正在尝试阅读BITMAPFILEHEADER和BITMAPINFOHEADER。但我每次都得0。我究竟做错了什么。我正在使用c ++。
#include <bits/stdc++.h>
using namespace std;
typedef int LONG;
typedef unsigned short WORD;
typedef unsigned int DWORD;
struct BITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
};
struct BITMAPINFOHEADER {
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
};
int main(void){
ifstream file("lena.bmp");
int begin = file.tellg();
file.seekg(0, ios::end);
int end = file.tellg();
int length = end-begin;
char* bf = new char[length+1];
file.read(bf, length+1);
BITMAPFILEHEADER* file_header = (BITMAPFILEHEADER*)(bf);
//BITMAPINFOHEADER* info_header = (BITMAPINFOHEADER*)(bf+sizeof(BITMAPFILEHEADER)-1);
cout << file_header->bfType << endl;
//cout << info_header->biSize << endl;
return 0;
}