取得位图的尺寸

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;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值