Hi,
I create a function like that (below)in C++ to draw a mat picture to HDC. I have use imshow to check and both image and cvImgTmp has been show correctly.
But my final picture look like that
I think I do something wrong with “bitInfo” or “SetDIBitsToDevice”
Are there anyone can help me to fix this.
Thank you
void DrawMatToHDC(const char* DicomPath, HDC hdc, RECT rc)// Developing
{
DicomImage DCM_image(DicomPath);
DCM_image.setWindow(0);
cv::Mat image(int(DCM_image.getWidth()), int(DCM_image.getHeight()), CV_8U, (uchar*)DCM_image.getOutputData(8));
cv::Size winSize(rc.right, rc.bottom);
//imshow("DICOM Image Example", image);
// Resize the source to the size of the destination image if necessary
cv::Mat cvImgTmp(winSize, CV_8UC3);
if (image.size() != winSize)
{
cv::resize(image, cvImgTmp, winSize);
}
else
{
cvImgTmp = image.clone();
}
//imshow("DICOM Image Example", cvImgTmp);
// Rotate the image
cv::flip(cvImgTmp, cvImgTmp, 0);
// Initialize the BITMAPINFO structure
BITMAPINFO bitInfo;
bitInfo.bmiHeader.biBitCount = 24;
bitInfo.bmiHeader.biWidth = winSize.width;
bitInfo.bmiHeader.biHeight = winSize.height;
bitInfo.bmiHeader.biPlanes = 1;
bitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitInfo.bmiHeader.biCompression = BI_RGB;
bitInfo.bmiHeader.biClrImportant = 0;
bitInfo.bmiHeader.biClrUsed = 0;
bitInfo.bmiHeader.biSizeImage = 0;
bitInfo.bmiHeader.biXPelsPerMeter = 0;
bitInfo.bmiHeader.biYPelsPerMeter = 0;
//
/*BITMAPINFOHEADER bi = { sizeof(bi) };
bi.biWidth = cvImgTmp.cols;
bi.biHeight = -cvImgTmp.rows;
bi.biBitCount = (WORD)(cvImgTmp.channels()*13);
bi.biPlanes = 1;*/
// Add header and OPENCV image's data to the HDC
SetDIBitsToDevice(hdc, 0, 0, cvImgTmp.cols, cvImgTmp.rows, 0, 0, 0, cvImgTmp.rows,
cvImgTmp.data, &bitInfo, DIB_RGB_COLORS);
/*SetDIBitsToDevice(hdc, 0, 0, cvImgTmp.cols, cvImgTmp.rows, 0, 0, 0, cvImgTmp.rows,
cvImgTmp.data, (BITMAPINFO*)&bi, DIB_RGB_COLORS);*/
}