您的位置:首页 > 其它

获取位图尺寸

2010-09-15 12:54 190 查看
从 CBitmap类对象中获取位图尺寸我们可用GetBitmap()函数 。


// 变量bitmap是一个CBitmap类对象


BITMAP bm;


bitmap.GetBitmap( &bm );


bmWidth = bm.bmWidth;


bmHeight = bm.bmHeight;

如果你有一个 HBITMAP句柄,你可以将它附加到一个CBitmap类对象上,再用上述方法
获取尺寸


// 变量hBmp是一个HBITMAP句柄


BITMAP bm;


::GetObject( hBmp, sizeof( bm ), &bm );


bmWidth = bm.bmWidth;


bmHeight = bm.bmHeight;

从BMP位图文件中获取位图尺寸可用下述方法。


CFile file;


// sBMPFileName是BMP位图文件名


if( !file.Open( sBMPFileName, CFile::modeRead) )


return ;




BITMAPFILEHEADER bmfHeader;




// 读文件头


if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader))


!= sizeof(bmfHeader))


return ;




// 确定文件类型标记’BM’


if (bmfHeader.bfType != ((WORD) (’M’ << 8) | ’B’))


return ;




BITMAPINFOHEADER bmiHeader;


if (file.Read((LPSTR)&bmiHeader, sizeof(bmiHeader))


!= sizeof(bmiHeader))


return ;




int bmWidth = bmiHeader.biWidth;


int bmHeight = bmiHeader.biHeight;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: