建立BMP映像

來源:互聯網
上載者:User
void Create_Image(){  FILE *fp;  int i,j;  unsigned char c, d;   BITMAPFILEHEADER *bitmapFileHeader;  BITMAPINFOHEADER *bitmapInfoHeader;   if((fp=fopen("b_1.bmp", "wb")) == NULL){    fprintf(stderr, "file cannot open\n");    exit(1);  }   /* 結構體指標初始化 */  bitmapFileHeader=(BITMAPFILEHEADER *)malloc(sizeof(BITMAPFILEHEADER));  bitmapInfoHeader=(BITMAPINFOHEADER *)malloc(sizeof(BITMAPINFOHEADER));   /*定義位元影像標頭檔資料結構*/  bitmapFileHeader->bfType = ('M'<<8)|'B';  bitmapFileHeader->bfReserved1 = 0x0000;  bitmapFileHeader->bfReserved2 = 0x0000;  //位元影像起始位置  bitmapFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);  /*定義位元影像資訊資料結構*/  bitmapInfoHeader->biSize = sizeof(BITMAPINFOHEADER);  int rate = 2;  bitmapInfoHeader->biWidth = IMAGE_X/rate;   bitmapInfoHeader->biHeight = IMAGE_Y/rate;  bitmapInfoHeader->biPlanes = 0x0001;  bitmapInfoHeader->biBitCount = 0x0018;  //24位元影像  bitmapInfoHeader->biCompression = 0x0000;  //不壓縮  /*每像素由RGB24位構成,即3位元組*/  bitmapInfoHeader->biSizeImage = bitmapInfoHeader->biWidth*bitmapInfoHeader->biHeight * 3;   /*位元影像檔案大小*/  bitmapFileHeader->bfSize = bitmapFileHeader->bfOffBits + bitmapInfoHeader->biSizeImage;   /*位元影像標頭檔結構寫入檔案*/  fwrite((unsigned char *)bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, fp);  /*位元影像資訊結構寫入檔案*/  fwrite((unsigned char *)bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, fp);   /*RGB顏色寫入檔案*/  for(j=IMAGE_Y-1;j>=0;j-=rate){    for(i=0;i<IMAGE_X;i+=rate){    c=(IMAGE[j*IMAGE_X + i])*1;  fprintf(fp, "%c%c%c",c,c,c);             /* RGB */    }  }    free(bitmapFileHeader);  free(bitmapInfoHeader);  fclose(fp);}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.