user20493
user20493

Reputation: 5804

Determine bits per pixel in a bitmap

What's the easiest way to tell the number of bits per pixel in a bitmap, e.g. a Windows .bmp file?

Upvotes: 0

Views: 2161

Answers (2)

Tanmay Roy
Tanmay Roy

Reputation: 11

//************************************** PROGRAM : To get the Number of bits per pixel of a bitmap.

AUTHOR : Tanmay Roy. - M.Tech(Embedded Sys & VLSI) (Kolkata,INDIA)

DATE : 20-May-2011

COMPILER: Visual Studio 6

REMARKS : It's done at very simple way, It works fine. This can be done at Turbo C also. but few modification neesed.

E-MAIL : [email protected]

//**************************************

FILE *fp; int bitPerPixel
BITMAPFILEHEADER    bfh;
BITMAPINFOHEADER    bih;

fp = fopen("C:\\MYPIC.BMP","rb"); // The picture whose 'bit per pixel' to get.

if(fp == NULL) 
{ 
AfxMessageBox("ERROR: file open err"); return(-1); 
}

fread(&bfh,sizeof(BITMAPFILEHEADER),1,fp); // Read Bitmap File Header
fread(&bih,sizeof(BITMAPINFOHEADER),1,fp); // Read Bitmap Info Header

/*  BITMAPFILEHEADER,BITMAPINFOHEADER are inbulit data type in VC++,MFC */

bitPerPixel = bih.biBitCount; 
fclose(fp); 

Upvotes: 1

NG.
NG.

Reputation: 22904

Look at the header of the file.

Upvotes: 1

Related Questions