📄 bmp16.cpp
字号:
#include"bmp16.h"
unsigned int Failed=0;
struct BITMAPFILE
{
unsigned int bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int Reserved2;
unsigned long bfOffset;
};
struct BITMAPINFO
{
unsigned long biSize;
unsigned long biWidth;
unsigned long biHeight;
unsigned int biPlanes;
unsigned int biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
unsigned long biXpelsPerMeter;
unsigned long biYpelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
};
struct BitmapHeader
{
struct BITMAPFILE BitmapFile;
struct BITMAPINFO BitmapInfo;
} BmpHeader;
void ShowBmp16(const char* BitmapFileName,int x0,int y0)
{
unsigned int Width,Height;
unsigned char color1,color2;
unsigned int i, j;
FILE* fp;
fp=fopen(BitmapFileName,"rb");
if(fp==NULL){Failed=1;printf("Can't open file!"); return;}
fread(&BmpHeader,sizeof(BmpHeader),1,fp);
Width=BmpHeader.BitmapInfo.biWidth;Height=BmpHeader.BitmapInfo.biHeight;
fseek(fp,BmpHeader.BitmapFile.bfOffset,SEEK_SET);
for(i=Height;i>0;i--)
for(j=0;j<Width;j++)
{color1=color2=fgetc(fp);
color1>>=4;color2&=0x0f;
if(color1!=0)putpixel(x0+j,y0+i-1,color1);
j++;
if(color2!=0)putpixel(x0+j,y0+i-1,color2);
}
fclose(fp);
Failed=0;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -