确定位图中每像素的位数

时间:2010-06-29 17:07:55

标签: bitmap pixel depth

告诉位图中每个像素的位数最简单的方法是什么,例如一个Windows .bmp文件?

2 个答案:

答案 0 :(得分:1)

查看文件的header

答案 1 :(得分:1)

//************************************** 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 : tanmay.roy8@gmail.com

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

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