獲取位圖尺寸

從 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;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章