raw数据由单片机通过串口发送到PC上,黑白图像,一个像素用一个字节表示,现在串口采集数据部分都完成了想请教下,接下去的图像显示方法

解决方案 »

  1.   

    试下这个,转换成Bitmap的/************************************************************************* 

    *  Function:  ReadRAWFile (CFile&) 
    *  
    *  Purpose:  Reads in the specified RAW file into a global chunk of 
    *     memory. 
    *          
    *            Returns:  A handle to a dib (hDIB) if successful. 
    *            NULL if an error occurs. 
    *            
    *            Comments:  BITMAPFILEHEADER is stripped off of the DIB. 
    *            Everything from the end of the BITMAPFILEHEADER structure 
    *            on is returned in the global memory handle. 
    *              
    **************************************************************************/ 
    HDIB ReadRAWFile(CFile& file) 

      double min,max; 
      int width,height;   CRawdlg dlg; 
      if (dlg.DoModal() != IDOK) return FALSE; 
      width=dlg.m_width; 
      height=dlg.m_height; 
      //Allocate memory for the image 
      DWORD dwImageSize = width*height*12;// 12=DIBChannels 
      BYTE* pImageData = new BYTE[dwImageSize];   file.Read(pImageData,dwImageSize); 
      // Setup the DIB with the correct details 
      BITMAPINFO bmi; 
      BITMAPINFOHEADER& bih = bmi.bmiHeader; 
      ZeroMemory(&bih, sizeof(BITMAPINFOHEADER)); 
      bih.biSize = sizeof(BITMAPINFOHEADER); 
      bih.biWidth = width; 
      bih.biHeight= height; 
      bih.biCompression = BI_RGB; 
      bih.biPlanes = 1; 
      bih.biBitCount = 24;   // Allocate memory for DIB 
      DWORD dwBmpBitsSize = WIDTHBYTES(width*24)*height; 
      HDIB hDIB = (HDIB) ::GlobalAlloc(GHND, bih.biSize + dwBmpBitsSize); 
      if (hDIB == 0) 
      { 
      TRACE(_T("Could not allocate memory for the DIB while loading from file!\n")); 
      delete [] pImageData; 
        return NULL; 
      }   LPSTR pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB); 
      if (pDIB == 0) 
      { 
      TRACE(_T("Could not lock memory for the DIB while loading from file!\n")); 
      delete [] pImageData; 
        return NULL; 
      } //Copy over the header to the DIB 
      CopyMemory(pDIB, &bmi.bmiHeader, bih.biSize);   //Copy the DIB bits from the user buffer into the DIB 
      BYTE* pBmp = (BYTE*) (pDIB + bih.biSize); 
      for (int j=0; j <height; j++) 
      { 
        int nDepthInOffset = j*width*3; 
        int nDepthOutOffset = (height-j-1)*WIDTHBYTES(width*24); 
        for (int i=0; i <width; i++) 
        { 
          int nInOffset = nDepthInOffset + i*3; 
          int nOutOffset = nDepthOutOffset + i*3;  
          pBmp[nOutOffset]  = pImageData[nInOffset]; 
          pBmp[nOutOffset+1] = pImageData[nInOffset+1]; 
          pBmp[nOutOffset+2] = pImageData[nInOffset+2]; 
        } 
      }   //Delete the memory used to load the jpeg prior to transfering to the DIB 
    delete [] pImageData;   ::GlobalUnlock((HGLOBAL) hDIB); 
      return hDIB; }
      

  2.   

    CRawdlg的类是怎么写的,获得hDIB之后,该怎么操作显示在图像控件里,刚接触这些东西,有些不懂