获取位图尺寸
2010-09-15 12:54
190 查看
从 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;
// 变量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;
相关文章推荐
- 获取位图尺寸
- 根据HBITMAP获取位图的尺寸信息
- 根据HBITMAP获取位图的尺寸信息
- 获取位图尺寸
- Android获取屏幕尺寸
- 获取视图尺寸大小方法
- 【转】JS获取浏览器可视区域的尺寸
- JS中获取元素的尺寸及位置
- React Native 获取屏幕的尺寸
- VC编程实现位图处理类(显示位图、加载位图、获取/设置像素点颜色)
- 上传图片前获取其尺寸
- php中使用getimagesize获取图片、flash等文件的尺寸信息实例
- java获取图片的尺寸(高和宽)
- 在jQuery中获取浏览器窗口的尺寸信息
- js动态获取图片长宽尺寸(兼容所有浏览器,速度极快)
- Android中的坐标及各种获取尺寸方法的含义
- [[UIScreen mainScreen] bounds]获取尺寸不对 解决
- 获取屏幕尺寸大小
- iOS 获取屏幕尺寸 设置背景图片
- JavaScript获取DOM元素位置和尺寸大小