I use an Imebra library to read DICOM files. I need to display DICOM image. Imebra library gives me an image in buffer (I follow this documentation):
load file
std::unique_ptr<DataSet> MyDataSet(CodecFactory::load("IM1"));
retrieving an image
Image* image(MyDataSet->getImageApplyModalityTransform(0));
int iWidth = image->getWidth();
int iHeight = image->getHeight();
TransformsChain chain;
if (ColorTransformsFactory::isMonochrome(image->getColorSpace()))
{
VOILUT voilutTransform;
vois_t vois = MyDataSet->getVOIs();
list<LUT*> luts;
for (size_t scanLUTs(0); ; ++scanLUTs)
{
try { luts.push_back(MyDataSet->getLUT(TagId(tagId_t::VOILUTSequence_0028_3010), scanLUTs)); }
catch (const MissingDataElementError&) { break; }
}
if (!vois.empty()) voilutTransform.setCenterWidth(vois[0].center, vois[0].width);
else if (!luts.empty()) voilutTransform.setLUT(*(luts.front()));
else voilutTransform.applyOptimalVOI(*image, 0, 0, iWidth, iHeight);
DrawBitmap draw(chain);
size_t requestedBufSize = draw.getBitmap(*image, drawBitmapType_t::drawBitmapRGBA, 4, 0, 0);
string buffer(requestedBufSize, char(0));
draw.getBitmap(*image, drawBitmapType_t::drawBitmapRGBA, 4, &buffer.at(0), requestedBufSize);
So I got a buffer with bitmap inside it. (following each word of documentation).
Then I get bitmap from this buffer:
hBitmap = CreateBitmap(iWidth, iHeight, 1, 24, buffer);
Now I'm trying to dispay it in MFC PictureControl (on dialog window):
void CImebraDlg::OnPaint()
{
CPaintDC dc(this);
CDC memdc;
BITMAP b;
//m_DicomImage - CStatic variable of PictureControl
m_DicomImage.GetClientRect(&rect);
::GetObject(theApp.hBitmap, sizeof(BITMAP), &b);
memdc.CreateCompatibleDC(&dc);
memdc.SelectObject(&bmp);
dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &memdc,
0, 0, b.bmWidth, b.bmHeight, SRCCOPY);
dc.MoveTo(0, 0);
}
And nothig happens, no image in PictureControl.
Trying like this:
void CImebraDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetImageToRictureControl(theApp.hBitmap);
}
void CImebraDlg::SetImageToRictureControl(HBITMAP hbmp)
{
m_DicomImage.SetBitmap(hbmp);
UpdateData(FALSE);
}
the same result... BITMAP structure you can see on the screenshot.
bmBits is NULL.. Is this the reason of not displaying dicom image? How to display a DICOM image right with imebra lib?