2013-11-21 68 views
0

我使用下面的代碼來顯示OpenCV的IplImage。它適用於RGB圖像。但對於灰色圖像(只有一個通道),圖像是倒置的(反轉)。使用SetDIBitsToDevice在MFC中顯示灰度圖像到圖片框

if(m_img && m_img->depth == IPL_DEPTH_8U) 
    { 
     uchar buffer[sizeof(BITMAPINFOHEADER) + 1024]; 
     BITMAPINFO* bmi = (BITMAPINFO*)buffer; 
     int bmp_w = m_img->width, bmp_h = m_img->height; 
     FillBitmapInfo(bmi, bmp_w, bmp_h, Bpp(), m_img->origin); 
     from_x = MIN(MAX(from_x, 0), bmp_w - 1); 
     from_y = MIN(MAX(from_y, 0), bmp_h - 1); 
     int sw = MAX(MIN(bmp_w - from_x, w), 0); 
     int sh = MAX(MIN(bmp_h - from_y, h), 0); 
     SetDIBitsToDevice(
      dc, x, y, sw, sh, from_x, from_y, from_y, sh, 
      m_img->imageData + from_y*m_img->widthStep, 
      bmi, DIB_RGB_COLORS); 
    } 

我看着功能鏈接here並表明lpvBits是RGB顏色。我如何修改灰度圖像? 感謝

回答

0

使用GDI +

  1. 裝入有色位圖
  2. 30%紅色59%綠 11%藍
  3. 創建嘉洛斯創建一個ImageAttributes
  4. 將ColorMatricx到ImageAttributes
  5. 創建一個新的位圖
  6. 使用DrawImage與Ima geAtributes並將彩色位圖繪製到新的位圖中。

有一小羣C#代碼示例,但C +中的GDI +接口幾乎完全相同。