获取文件信息失败

zjugrief 2013-05-17 04:54:24
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总是错误的,求教错误原因
...全文
483 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjugrief 2013-05-17
  • 打赏
  • 举报
回复
我顶
diyuqingjie 2013-05-17
  • 打赏
  • 举报
回复
大神快来

19,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧