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

  • Fake Oakley Drizzle low price for sale

    Posted by sjvwoqjem on 06/26/2013 06:14pm

    Ray Ban Clearance ,Oakley sunglasses created to change annually, the same as another style?? However, the alternatives are very different game situations, there isn't a truly fashion. The fashion brand focuses around the trend of glasses exist within the field strengthened. These measures include high-end luxury brands in Europe, as well as contemporary U.S. brand Brooks Brothers at the top to take into account. Fake Oakleys ,Oakley ski goggles will give you amazing feeling, the most up-to-date model and design more pleasing and stylish glasses. The unique design and precision manufacturing touch, in the brand, to ensure each set of two sunglasses masterpiece. They'll agree in a style, design and elegance. Oakley bIg taco Sunglasses ,Will be difference between and ordinary OAKLEY sunglasses discount? This is a a number of sizes, shapes and fashoins to demonstrate off your attitude, discussing with you, and to echo your personality. There is no need the very best of the most beneficial to obtain the best. You truly can give the elements on the show too although if you need to alter the look of your face, it really is easy. To find out nowhere, pale yellow and pink lenses are not made for wear in bright light, his or her anti-reflective capacity is weak. Women waiting to get combined with the usage of previously they would choose to purchase additional, nearly every period of a performance together for his or her special handbags purses and handbags, in many months. The most protection on the eyes, HDO upgrade lens 100% UV filtering also produces the most important and best quality mats to make the certain durability. Concisely, not during the summer time of Oakley sun screen lotion, close to noon, for the Four Seasons, the surrounding sea or sailing or at high altitude snowboarding. Oakley sunglasses shape and stainless metal injection molding, setting up a convenient button to discharge each shot, the handle towards smallest detail. A perpetual lens coating in order to avoid rain and sweat building for the lens, the exclusion of skin oils as well as other contaminants, so the lens is smudge and easy to hold clean. OAKLEY truly accurate optical technology, expensive Strengthening research for countless years along with the firm manufacturing. You can find the best company, providing high-quality products, budget friendly cost towards the minutes of the best pattern, variety, sunglasses add-ons monitor.

    Reply
  • 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
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds