请帮忙指导一下,我查阅了好多资料都找不到正解!
/*第一部分为位图文件头BITMAPFILEHEADER,其定义如下:*/
typedef struct tagBITMAPFILEHEADER
{
unsigned int bfType; /*指定文件类型,*.bmp文件的头两个字节都是"BM"*/
unsigned long bfSize; /*指定文件大小,包括这14个字节*/
unsigned int Reserved1; /*为保留字,不用考虑*/
unsigned int reserved2; /*为保留字,不用考虑*/
unsigned long bfOffset; /*为从文件头到实际的位图数据的偏移字节数,前三个部分的长度之和。*/
}BITMAPFILEHEADER;
/*第二部分为位图信息头BITMAPINFOHEADER,这个结构的长度是固定的,为40个字节其定义如下:*/
typedef struct tagBITMAPINFOHEADER
{
unsigned long biSize; /*指定这个结构的长度,为40*/
unsigned long biWidth; /*指定图象的宽度,单位是象素*/
unsigned long biHeight; /*指定图象的高度,单位是象素*/
unsigned int biPlanes; /*必须是1,不用考虑*/
unsigned int biBitCount; /*指定表示颜色时要用到的位数,常用的值为1(黑白二色图),4(16色图),8(256色),24(真彩色图)*/
unsigned long biCompression; /*指定位图是否压缩,有效的值为BI_RGB,BI_RLE8,BI_RLE4,BI_BITFIELDS*/
unsigned long biSizeImage; /*指定实际的位图数据占用的字节数*/
unsigned long biXpolsPerMeter; /*指定目标设备的水平分辨率,单位是每米的象素个数。*/
unsigned long biYpelsPerMeter; /*指定目标设备的垂直分辨率,单位同上。*/
unsigned long biClrUsed; /*指定本图象实际用到的颜色数,如果该值为零,则用到的颜色数为2的biBitCount次方。*/
unsigned long biClrImportant; /*指定本图象中重要的颜色数,如果该值为零,则认为所有的颜色都是重要的。*/
}BITMAPINFOHEADER;
typedef struct tagRGBQUAD /*用于读取调色板信息*/
{
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char Reserved;
}RGBQUAD;
typedef struct tagRGB
{
unsigned char r;
unsigned char g;
unsigned char b;
}RGB24;
我依照NEO的子程序,可是24K的BMP图片显示不出来,请指点?
#define SRGB332(r, g, b) ((((r) / 9) << 5) + (((g) / 9)<<2) + (b) / 21)
void Show_BMP(char *File_Name, int x, int y)
{
int i, j, width, color,len;
FILE *fp;
unsigned char *buffer;
RGB24 *RGB_buffer;
RGBQUAD *RGB;
BITMAPFILEHEADER *FileHead;
BITMAPINFOHEADER *InfoHead;
if ((fp=fopen(File_Name,"rb")) == NULL)
{
printf("BMP File not exist ...");
return;
}
RGB = (RGBQUAD *)malloc(sizeof(RGBQUAD));
FileHead = (BITMAPFILEHEADER *)malloc(sizeof(BITMAPFILEHEADER));
InfoHead = (BITMAPINFOHEADER*)malloc(sizeof(BITMAPINFOHEADER));
fread(FileHead,sizeof(BITMAPFILEHEADER),1,fp);
if (FileHead->bfType!='BM')
{
printf("BMP File type Error ...");
return;
}
fread(InfoHead,sizeof(BITMAPINFOHEADER),1,fp);
if (InfoHead->biCompression !=0 || (InfoHead->biBitCount!=8 && InfoHead->biBitCount!=24))
{
printf("BMP File not Support Compression type ...");
fclose(fp);
return;
}
width =((int)InfoHead->biWidth+3)/4*4; // 每行字节数--4的整数倍
if ((buffer = (unsigned char *)malloc(width)) == NULL) // 申请缓冲区
{
fclose(fp);
return;
}
if ((int)InfoHead->biBitCount == 8) // 色深=8
{
for (i = 0 ; i < 256 ; i++)
{
fread(RGB,sizeof(RGBQUAD),1,fp);
outportb(0x3C8,i);
outportb(0x3C9,RGB->rgbRed>>2);
outportb(0x3C9,RGB->rgbGreen>>2);
outportb(0x3C9,RGB->rgbBlue>>2);
}
for (j = (int)InfoHead->biHeight-1 ; j >= 0 ; j--)
{
fread(buffer,width,sizeof(unsigned char),fp);
for (i = 0; i < width; i++)
PutPixel(i+x,j+y,buffer[i]);
}
}
else if ((int)InfoHead->biBitCount == 24) // 色深=24
{
len=(int)InfoHead->biWidth*sizeof(RGB24)+(int)InfoHead->biWidth&3;
if ((RGB_buffer = (RGB24 *)malloc(len)) == NULL)
{
fclose(fp);
return;
}
for (j = (int)InfoHead->biHeight-1 ; j >= 0 ; j--)
{
fread(RGB_buffer,len,sizeof(char),fp); /*读取该行像素的所有点的颜色*/
for (i=0;i<len;i++)
{
color = SRGB332(RGB_buffer[i].r,RGB_buffer[i].g,RGB_buffer[i].b);
PutPixel(i+x,j+y,color);
}
}
}
free(FileHead);
free(InfoHead);
free(RGB);
}