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顏色。我如何修改灰度圖像? 感謝