获取文件信息失败

zjugrief zjugrief 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
bool mydlg::LoadImageBuffer(HDC memdc,char *szFileName)
{

BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
BITMAPINFO bitmapinfo;

int file_hand;

OFSTRUCT file_data;

file_hand = OpenFile(szFileName,&file_data,OF_READ);


if (file_hand==-1)
return 0;


_lread(file_hand, &bitmapfileheader,sizeof(BITMAPFILEHEADER));

// test if this is a bitmap file
if (bitmapfileheader.bfType != ((WORD) ('M' << 8) | 'B'))
{
// close the file
_lclose(file_hand);
// return error
return 0;
} // end if

// now we know this is a bitmap, so read in all the sections

// first the bitmap infoheader

// now load the bitmap file header
_lread(file_hand, &bitmapinfoheader, sizeof(BITMAPINFOHEADER));

if (bitmapinfoheader.biWidth%4 != 0) // 宽度不是4的倍数
{
MessageBox("文件宽度不是4的倍数");
_lclose(file_hand);
return 0;
}

if(g_pImgBuffer) // clear it if not null
delete[] g_pImgBuffer;
g_pImgBuffer = new RGB[g_nMapHeight * g_nMapWidth]; // make space

// now load the color palette if there is one
if (bitmapinfoheader.biBitCount != 24)
{
// set bitmapinfo
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo.bmiHeader.biWidth = g_nMapWidth;
bitmapinfo.bmiHeader.biHeight = g_nMapHeight;
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biBitCount = 24;
bitmapinfo.bmiHeader.biCompression = BI_RGB;
GetDIBits(memdc, g_hBitmap, 0, g_nMapHeight, NULL,
&bitmapinfo, DIB_RGB_COLORS);
GetDIBits(memdc, g_hBitmap, 0, g_nMapHeight, g_pImgBuffer,
&bitmapinfo, DIB_RGB_COLORS);
}
else
{
_llseek(file_hand, bitmapfileheader.bfOffBits,FILE_BEGIN);
_lread(file_hand, g_pImgBuffer, 3*g_nMapHeight*g_nMapWidth);
}




// close the file
_lclose(file_hand);

// return success
return 1;
}

图片已经加载,即szFileName获取正确,可是调试发现bitmapfileheader总是错误的,求教错误原因
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
zjugrief
图形处理/算法 19,463 成员 50,678 内容