Image output

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
PandOS
Posts: 5
Joined: Mon, 2018-04-23, 08:33

Image output

#1 Post by PandOS »

Good afternoon! Can not output image .. Help please

Code: Select all

void MainDlg::OnOpen()
{
	CFileDialog fileDlg(TRUE, NULL, (CString)"*.dcm");
	INT_PTR result = fileDlg.DoModal();	
	if (result==IDOK)	
	{
		CString str1 = fileDlg.GetPathName();
		char *str;
		str = str1.GetBuffer(str1.GetLength());
		str1.ReleaseBuffer();
		image = new DicomImage(str);

		image->setMinMaxWindow();
		Uint8 *pixelData = (Uint8 *)(image->getOutputData(8));
		if (pixelData != NULL){
			int w = image->getWidth();
			int h = image->getHeight();

			HBITMAP hBitmap = NULL;		

			BITMAPINFOHEADER bmih;
			bmih.biSize = sizeof(BITMAPINFOHEADER);
			bmih.biWidth = w;
			bmih.biHeight = -h;
			bmih.biPlanes = 1;
			bmih.biBitCount = 8;
			bmih.biCompression = BI_RGB ;
			bmih.biSizeImage = 0;
			bmih.biXPelsPerMeter = 10;
			bmih.biYPelsPerMeter = 10;
			bmih.biClrUsed = 0;
			bmih.biClrImportant = 0;

			BITMAPINFO dbmi;
			ZeroMemory(&dbmi, sizeof(dbmi));  
			dbmi.bmiHeader = bmih;
				dbmi.bmiColors[0].rgbBlue = 0;
				dbmi.bmiColors[0].rgbGreen = 0;
				dbmi.bmiColors[0].rgbRed = 0;
				dbmi.bmiColors[0].rgbReserved = 0;
				void* bits = (void*)&(pixelData[0]); 

			// Create DIB
			HDC localDC = ::GetDC(NULL);
			hBitmap = CreateDIBSection(localDC, &dbmi, DIB_RGB_COLORS, &bits, NULL, 0);
			if (hBitmap == NULL) {
				::MessageBox(NULL, __T("Could not load the desired image image"), __T("Error"), MB_OK);
				return;
			}

			unsigned char* dest = new unsigned char[w*h*3];
			dest =	(unsigned char*)bits;
			const unsigned char* src  = new const unsigned char[w*h*3];
			src = (BYTE* )pixelData;
			for (int j=0; j<w; j++){
				for (int i=0; i<h; i++, src++){
					*dest++ = *src;
					*dest++ = *src;
					*dest++ = *src;
				}
			}

			m_picture.SetBitmap(hBitmap);
			delete dest;
			delete src;
		}		
	}
}

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Image output

#2 Post by J. Riesmeier »

DicomImage::getOutputData() does not always return RGB pixel data, e.g. in case the DICOM image is monochrome. Also padding and the like is not as expected by the Windows API. I would therefore suggest that you use DicomImage::createWindowsDIB() instead.

PandOS
Posts: 5
Joined: Mon, 2018-04-23, 08:33

Re: Image output

#3 Post by PandOS »

J. Riesmeier wrote:DicomImage::getOutputData() does not always return RGB pixel data, e.g. in case the DICOM image is monochrome. Also padding and the like is not as expected by the Windows API. I would therefore suggest that you use DicomImage::createWindowsDIB() instead.
Thank you so much! Understood now.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest