欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>杂项>>文章内容
取得位图的尺寸
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
  http://{域名已经过期}/document/

Getting the dimensions of a bitmap


For CBitmap objects we can use the GetBitmap() function to determine the height and width of the bitmap.

	// The variable bitmap is a CBitmap object

	BITMAP bm;

	bitmap.GetBitmap( &bm );

	bmWidth = bm.bmWidth;

	bmHeight = bm.bmHeight;

If you have a HBITMAP, you can attach it to a CBitmap object and use the method shown above or you can use

	// The variable hBmp is a HBITMAP

	BITMAP bm;

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

	bmWidth = bm.bmWidth;

	bmHeight = bm.bmHeight;

For images in a BMP file, you can use something like

	CFile file;

	// sBMPFileName is the BMP filename

	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;



附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步