我需要從bmp中獲取寬度和高度值,以便在稍後從位圖中的原始像素數據創建gdk像素圖時,可以將這些值作爲參數傳遞。 我做的BMP格式和文件頭的一些研究應該是這樣的:從cpp中的mysql blob解析BMP文件
struct Fileheader
{
unsigned short Type; // signature - 'BM'
unsigned long Size; // file size in bytes
unsigned short Reserved1; // 0
unsigned short Reserved2; // 0
unsigned long OffBits; // offset to bitmap
unsigned long StructSize; // size of this struct (40)
unsigned long Width; // bmap width in pixels
unsigned long Height; // bmap height in pixels
unsigned short Planes; // num planes - always 1
unsigned short BitCount; // bits per pixel
unsigned long Compression; // compression flag
unsigned long SizeImage; // image size in bytes
long XPelsPerMeter; // horz resolution
long YPelsPerMeter; // vert resolution
unsigned long ClrUsed; // 0 -> color table size
unsigned long ClrImportant; // important color count
Fileheader()
{
Size=Width=Height=Planes=BitCount=Compression=SizeImage=XPelsPerMeter= YPelsPerMeter=ClrUsed=ClrImportant=Type=StructSize=Reserved1=Reserved2=OffBits=0;}
};
}
取斑標準的方式進入行之後[0]
Fileheader fh;
memcpy(&fh, row[0], sizeof(Fileheader));
會給只是胡言亂語值當
cout << "width: " << fh.Width << ", height: " << fh.Height << endl;
即:寬度:65536,高度:5626121834492592128
有人看到這裏有什麼問題嗎?順便說一句,我在一個64位的Linux機器上。
tyty,你的建議做到了。爲什麼不鼓勵? – Paul