获得BMP文件的长宽

在用Direct Draw开发的时候,在建立表面的时候,要知道贴上的图片的宽度。如果用手动输入的话,不够灵活。查了一下MSDN,使用下面的方法,顺利解决。

void AddBMPFile( char * szfilepath)
{
if ( NULL == szfilepath) return;
BITMAP bm;
HBITMAP hbitmap;
int  nWidth ,nHeight;
hbitmap = (HBITMAP) LoadImage(NULL, szfilepath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
GetObject(hbitmap, sizeof(bm), &bm);
nWidth = bm.bmWidth; //所求的宽
nHeight = bm.bmHeight;//所示的高
}/*AddBMPFile*/

发表评论





XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>