设为首页 加入收藏

TOP

得到位图的尺寸
2014-11-23 20:10:08 来源: 作者: 【 】 浏览:5
Tags:得到 位图 尺寸

对于一个CBitmap 对象,我们能用GetBitmap() 函数来确定其宽度和高度。

// The variable bitmap is a CBitmap object bitmap变量是一个CBitmap对象

BITMAP bm;

bitmap.GetBitmap( &bm );

bmWidth = bm.bmWidth;

bmHeight = bm.bmHeight;

如果你有一个HBITMAP位图句柄,你可以将它附属于一个CBitmap对象,然后用上面讲到的方法或下面的方法来确定其宽度和高度。

// The variable hBmp is a HBITMAP hBmp变量是一个HBITMAP位图句柄

BITMAP bm;

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

bmWidth = bm.bmWidth;

bmHeight = bm.bmHeight;

对于一个文件,你能用下面的代码来实现:

CFile file;

// sBMPFileName is the BMP filename sBMPFileName是一个位图文件名

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

return ;

BITMAPFILEHEADER bmfHeader;

// Read file header 读文件头信息

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

return ;

// File type should be 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;

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇闪屏图形特技效果的实现 下一篇在对话框中动态显示位图

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: