Getting the dimensions of a bitmap
Posted
by Zafir Anjum
on October 1st, 2002
// 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:23pmCan anyone help me how to get the RGB values of BMP, PNG and JPEG image file formats? in c/c++ plz.. Thank you...
ReplyWhere can I find information about Bitmap
Posted by Kambiz on 02/25/2007 01:33pmI 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
Replyhow to get 704X576 pixel bitmat in VC++
Posted by ushaji_cs on 04/01/2006 01:48ami 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.
ReplyHow to read a bmp image into an array buffer in openGL
Posted by Legacy on 02/26/2004 12:00amOriginally posted by: Barun Sarker
hello!
Replykindly send me the code to read the bmp image pixel by pixel and store it in an array using openGL
to obtain the pixel map of a .bmp image
Posted by Legacy on 02/17/2004 12:00amOriginally posted by: nathalie
Replyto display an bmp image in linux env using a c program
Posted by Legacy on 02/17/2004 12:00amOriginally posted by: naveen
hi
Replycan 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.
Displaying 8bit images from file onto dialog and increase the brightness as required
Posted by Legacy on 01/07/2004 12:00amOriginally posted by: Raghavendra
Replyc
Posted by Legacy on 12/15/2003 12:00amOriginally posted by: jeeva
how to read bitmap files in c?
Replyhow 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 12:00amOriginally 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?
Replyto display bitmap image file &clip it as desired by user
Posted by Legacy on 10/29/2003 12:00amOriginally 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.
ReplyLoading, Please Wait ...