当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
24位位图格式解析
发布时间:2010/8/24 10:36:16 来源:城市学习网 编辑:ziteng
  每一行的图素数等于该结构的bcWidth字段。每一行从最左边的图素开始,直到图像的右边。分别对应的B,G,R像素。每个像素占8位, 每列的宽度为bcWidth,必须为4的倍数,不足的用零填充。
  下面是读取二十四位位图的关键代码:
  代码
  1 BITMAPFILEHEADER * pbmfh ;
  2 BITMAPINFO       * pbmi ;
  3 BYTE             * pBits ;
  4 pbmfh = DibLoadImage (szFileName) ;
  5 pbmi  = (BITMAPINFO *) (pbmfh + 1) ;
  6 pBits = (BYTE *) pbmfh + pbmfh->bfOffBits ;
  7 for( i=0; i < 1024; i++)
  8 {
  9     pPrintBlock[i] =  (char*)malloc(216);
  10     memset(pPrintBlock[i], 0, 216);
  11 }
  12
  13 for(h = 0; h <  pbmi->bmiHeader.biHeight; h++)
  14 {
  15     for(w = 0; w <  pbmi->bmiHeader.biWidth; w++)
  16     {
  17         b1 = *pBits;          //B
  18         b2 = *(pBits+1);      //G
  19         b3 = *(pBits+2);      //R
  20         if( (int)b1 != 255 && (int)b2 != 255 && (int)b3 != 255)
  21         {
  22             index = w / 8;
  23             index = 1 << (w%8);
  24             index = pPrintBlock[h][w / 8] | ( 1 << (w%8) );
  25             pPrintBlock[h][w / 8] = pPrintBlock[h][w / 8] | ( 1 << (w%8) );
  26         }
  27         pBits += 3;
  28
  29     }
  30     if(pbmi->bmiHeader.biWidth *3 % 4 != 0)
  31     {
  32         pBits += ( 4 - pbmi->bmiHeader.biWidth*3 % 4);
  33     }
  34 }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved