opencv的圖象格式IplImage 和CBitmap的轉換

來源:互聯網
上載者:User
 BOOL IplImage2Bmp(HDC dc,IplImage *pImage,CBitmap *bitmap){ if( pImage && pImage->depth == IPL_DEPTH_8U )    {        uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];        BITMAPINFO* bmi = (BITMAPINFO*)buffer;        int bmp_w = pImage->width, bmp_h = pImage->height;         //FillBitmapInfo( bmi, bmp_w, bmp_h, Bpp(), pImage->origin );  int width=bmp_w;  int height=bmp_h;  int bpp=pImage ? (pImage->depth & 255)*pImage->nChannels : 0;  int origin=pImage->origin;  HBITMAP hBitmap;  char* dst_data = 0;   assert( bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32));   BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);   memset( bmih, 0, sizeof(*bmih));  bmih->biSize = sizeof(BITMAPINFOHEADER);  bmih->biWidth = width;  bmih->biHeight = origin ? abs(height) : -abs(height);  bmih->biPlanes = 1;  bmih->biBitCount = (unsigned short)bpp;  bmih->biCompression = BI_RGB;   if( bpp == 8 )  {   RGBQUAD* palette = bmi->bmiColors;   int i;   for( i = 0; i < 256; i++ )   {    palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;    palette[i].rgbReserved = 0;   }  }  if(bitmap->m_hObject!=NULL)  {   bitmap->Detach();  }  hBitmap=CreateDIBitmap(dc,bmih,CBM_INIT,pImage->imageData,bmi,DIB_RGB_COLORS);  bitmap->Attach(hBitmap);  return TRUE;    } return FALSE; }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.