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;



Comments

  • Getting RGB values from BMP, PNG and JPEG

    Posted by jahly on 11/12/2007 08:23pm

    Can anyone help me how to get the RGB values of BMP, PNG and JPEG image file formats? in c/c++ plz.. Thank you...

    Reply
  • Where can I find information about Bitmap

    Posted by Kambiz on 02/25/2007 01:33pm

    I am new (with Visual c++ and MFC) I tried to show a bitmap but couldn't. All CBitmap HBitmap & Bitmap is too much. Where can i find more info about how to handle with Bitmaps? Anybody who can help me with show a Bitmap or even better where I can find more info? thanks

    Reply
  • how to get 704X576 pixel bitmat in VC++

    Posted by ushaji_cs on 04/01/2006 01:48am

    i am getting the image format 352X288 pixel format i want a big size 704X576 pixel format. when i am calling the video format dialog it is automatically going to 352X288 pixel format, but in windows 98 its comming properly , but in windows Xp it is not working.

    Reply
  • How to read a bmp image into an array buffer in openGL

    Posted by Legacy on 02/26/2004 12:00am

    Originally posted by: Barun Sarker

    hello!
    kindly send me the code to read the bmp image pixel by pixel and store it in an array using openGL

    Reply
  • to obtain the pixel map of a .bmp image

    Posted by Legacy on 02/17/2004 12:00am

    Originally posted by: nathalie

    Hello,
    
    I want to have a list of the pixels contained in a .bmp image.
    I think I could store them in a buffer.
    But does anyone know which function is appropriate to do this?
    After that, the buffer of pixels will be used in an OpenGL application (written in Visual Basic).
    If you know a better way to analyse a .bmp image in OpenGL, tell me.
    Thank you :-)

    Reply
  • to display an bmp image in linux env using a c program

    Posted by Legacy on 02/17/2004 12:00am

    Originally posted by: naveen

    hi
    can u send me a C code to open a bmp image and extract all its characters in structure,also to display it in linux env.

    Reply
  • Displaying 8bit images from file onto dialog and increase the brightness as required

    Posted by Legacy on 01/07/2004 12:00am

    Originally posted by: Raghavendra

    How to display a 8bit image from file and how to perform brightness operation on the displayed file.Please help me
    

    Reply
  • c

    Posted by Legacy on 12/15/2003 12:00am

    Originally posted by: jeeva

    how to read bitmap files in c?
    how to write bitmap files in c?

    Reply
  • How can i change a CBitmap object to an other CBitmap object

    Posted by Legacy on 11/17/2003 12:00am

    Originally posted by: Fernando

    i put this in c++
    CBitmap object1, object2, temp;

    temp = object1;
    object1 = object2;
    object2 = temp;

    and this gets me an error, because i can't use '=' with a CBitmap object, how can i do that?

    Reply
  • to display bitmap image file &clip it as desired by user

    Posted by Legacy on 10/29/2003 12:00am

    Originally posted by: pushpa kumari

    how to display a bitmap image stored in a file through cor c++ program.&to clip it in small peices of images.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date