Virtual Developer Workshop: Containerized Development with Docker

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.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
	::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 ;


	// 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 ;

	if (file.Read((LPSTR)&bmiHeader, sizeof(bmiHeader)) != sizeof(bmiHeader))
		return ;

	int bmWidth = bmiHeader.biWidth;
	int bmHeight = bmiHeader.biHeight;


  • Getting RGB values from BMP, PNG and JPEG

    Posted by jahly on 11/13/2007 04:23am

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

  • Where can I find information about Bitmap

    Posted by Kambiz on 02/25/2007 09: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

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

    Posted by ushaji_cs on 04/01/2006 09: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.

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

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

    Originally posted by: Barun Sarker

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

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

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

    Originally posted by: naveen

    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.

  • to obtain the pixel map of a .bmp image

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

    Originally posted by: nathalie

    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 :-)

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

    Posted by Legacy on 01/07/2004 08: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

  • c

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

    Originally posted by: jeeva

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

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

    Posted by Legacy on 11/17/2003 08: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?

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

    Posted by Legacy on 10/29/2003 08: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.

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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