bmp.c

来自「本源码实现了bmp图像的读取与显示」· C语言 代码 · 共 55 行

C
55
字号
int sModel;
int huge Return_SVGA64K()
{
  return(sModel);
}

typedef struct
{
  unsigned char b;
  unsigned char g;
  unsigned char r;
}
rgb16M;

void putpoint65536(int x, int y, rgb16M color)
{
  setrgbpalette(1026, color.r >> 3, color.g >> 2, color.b >> 3);
  putpixel(x, y, 0);
}
char dir[12];
int showBMP(int x,int y,char BMPdir[12],int showBMPmodel)
{
  int width,height, i = DETECT, j = 0, x0, y0, fp;
  char fix;
  rgb16M *buffer;
  sModel=showBMPmodel;
  installuserdriver("Svga64K",Return_SVGA64K);
  initgraph(&i, &j, "");

  if((fp = open(BMPdir, O_RDONLY | O_BINARY)) == -1)
  {
    puts("Can't find file.");
    return 1;
  }
  lseek(fp, 18, SEEK_SET);
  read(fp, &width, 4);
  read(fp, &height, 4);
  fix = width % 4;
  lseek(fp, 54, SEEK_SET);
  buffer = (rgb16M *)malloc(width*sizeof(rgb16M));

  for(j = height - 1; j >= 0; j--)
  {
    read(fp, buffer, width*sizeof(rgb16M));
    lseek(fp, fix, SEEK_CUR);
    for(i = 0; i < width; i++)
      putpoint65536(x + i, y + j, buffer[i]);
  }
  free(buffer);
  close(fp);
  getch();
  closegraph();
  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?