已知一个图象文件保存在一个BYTE数组中,一个BYTE代表一个pixel
gray[512][512],实际上是去除BMP格式头的256 色的BMP图象数据。
现在要显示这个文件
如何处理

解决方案 »

  1.   

    用CreateDIBitmap函数,同时需要你提供调色板数据,
      

  2.   

    Below  is  a  code  which  use  data  in  array    "data  "  to  make  a  256  color  graylevel  bitmap  and  place  it  on  the  screen  with  the  use  of  BitBlt.I  hope  it  helps  whoever  needs  such  a  code.Let  me  know  weather  it  is  helpful  or  not  for  you.  
     
     
         BYTE  *datas;  
         int  i,j,k=0;  
         CClient  DC(AfxGetMainWnd());  
         BITMAPINFO  *BitInfo;  
         BitInfo=new  BITMAPINFO;  
         BitInfo-  >bmiHeader.biSize=sizeof  (BITMAPINFOHEADER);  
         BitInfo-  >bmiHeader.biWidth=col;  
         BitInfo-  >bmiHeader.biHeight=-row;  
         BitInfo-  >bmiHeader.biPlanes=1;  
         BitInfo-  >bmiHeader.biBitCount=8;  
         BitInfo-  >bmiHeader.biCompression=0;  
                 
         CDC  memDC;  
         memDC.CreateCompatibleDC(&DC);  
     
         HBITMAP  hbmp=CreateDIBSection(memDC.m_hDC,  
                                                                   BitInfo,  
                                                       DIB_RGB_COLORS,  
                                                       (void  **)&datas,  
                                                       NULL,  
                                                       0);  
         HBITMAP  oldBmp=(HBITMAP)SelectObject(memDC.m_hDC,hbmp);  
                                                                                                         
         int  nColors=256;  
         RGBQUAD    *pRGB;  
         pRGB  =  new  RGBQUAD[nColors];  
         for  (i=0;  i  <256;  i++)  {  
               pRGB[i].rgbRed=i;  
               pRGB[i].rgbGreen=i;  
               pRGB[i].rgbBlue=i;  
               pRGB[i].rgbReserved=0;  
         }  
     
         ::SetDIBColorTable(memDC.m_hDC,0,nColors,pRGB);  
     
         for(i=0;i  <row;i+=decimation)  
                     for(j=0;j  <col;j+=decimation)  
                       datas[k++]=data[i][j]*scale;  
     
         DC.BitBlt(_point.x,_point.y,col,row,&memDC,  0,0,SRCCOPY);  
     
         DeleteObject(hbmp);  
         delete  BitInfo;  
         delete  pRGB;  
     
     
    Submitted  By:  Mehdi  Esnaashari  (2002/03/09)  
      

  3.   

    谢谢masterz()
    你的代码的意思是不是自己构造bmp图象的文件头信息,然后把文件头信息和图象数据一起组成一个bmp文件,然后定义色表,显示图象?
    我对图象处理方面不是很熟悉,有什么相关网站或则有什么好的书推荐吗?
      

  4.   

    BYTE  *datas;  HBITMAP  hBitmap;
    //画像のデータを取得する。
    LPBITMAPINFO lpBitmap; 
    lpBitmap=(BITMAPINFO*) new BYTE[sizeof(BITMAPINFOHEADER) +  
    GetColorNumber(8 * img->nChannels) * sizeof(RGBQUAD)]; 
    lpBitmap->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 
    lpBitmap->bmiHeader.biWidth=100;
    lpBitmap->bmiHeader.biHeight=100;
    lpBitmap->bmiHeader.biBitCount=(WORD)(8 * 1);
    lpBitmap->bmiHeader.biPlanes=1; 
    lpBitmap->bmiHeader.biCompression=BI_RGB;
    lpBitmap->bmiHeader.biSizeImage=0;
    lpBitmap->bmiHeader.biClrUsed=0; 
    BYTE* bits = (BYTE *) datas;
    //HBITMAP画像をクリエートする。
    CDC dc;
    dc.CreateDC("DISPLAY", "DISPLAY", 0, 0);    
    hBitmap = CreateDIBitmap(dc.m_hDC,&lpBitmap->bmiHeader,CBM_INIT,bits,lpBitmap,DIB_RGB_COLORS|DIB_RGB_COLORS);
    DeleteDC(dc);
    //HBITMAP画像をリターンする。
    return hBitmap;
      

  5.   

    我用SetPixel一个一个点画倒是能画出来,不过效率很低,一张图的显示过程都看得到(一张图大概0.5秒左右,从上到下)如果按masterz()的方法做,显示出来的图象很模糊,而且有彩色斑点,不知道为什么另外我想问一下,我想先把图画到内存中,然后再画出来,但是我用的是memDC.SetPixel,这样的话好象不行。有什么解决办法