2

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.

enter image description here

bmBits is NULL.. Is this the reason of not displaying dicom image? How to display a DICOM image right with imebra lib?

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
Nika_Rika
  • 613
  • 2
  • 6
  • 29
  • 2
    Separation of concerns. First make sure DICOMM part works, by let's say dumping bitmap into .bmp file and examining it (you might need it for for debugging purposes later anyway). Then make sure your MFC code can show an arbitrary, correct bitmap (let's say from any .bmp file that you found on internet). Then stick two functionalities together by circumventing file read-write operations. There were plugins for Visual Studio that may help to visualize bitmaps just like you visualizing struct contents on your screenshot. – Ivan Aksamentov - Drop Oct 05 '16 at 09:19
  • After quick glance over source code here are some notes: (1) you probably want to use `std::vector` instead of `std::string` as a buffer for `draw.getBitmap(...)` (2) There might be a problem due to the fact that you are using signed chars for this buffer. Otherwise, please provide a [MCVE](http://stackoverflow.com/help/mcve). – Ivan Aksamentov - Drop Oct 05 '16 at 09:30
  • 2
    You cannot pass the string directly to CreateBitmap, you have to get the pointer to the data and set the number of bits to 32 (you are retrieving a RGBA image): CreateBitmap(iWidth, iHeight, 1, 32, &buffer.at(0)) – Paolo Brandoli Oct 05 '16 at 10:43
  • Additionaly, you should retrieve a drawBitmapBGRA image (on Windows, RGB are reversed). – Paolo Brandoli Oct 05 '16 at 10:44
  • Yeah, the reason was in CreateBitmap. Now I will study how to extract all the images from a file. Your documentation helps a lot!!Thank you! – Nika_Rika Oct 05 '16 at 10:56

0 Answers0