当前位置:编程学习 > C/C++ >>

得到位图的尺寸

 

 

对于一个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;

 

 

补充:软件开发 , C语言 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,