Determine bits per pixel in a bitmap

心已入冬 提交于 2019-12-11 16:43:43

问题


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


回答1:


Look at the header of the file.




回答2:


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


来源:https://stackoverflow.com/questions/3143022/determine-bits-per-pixel-in-a-bitmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!