Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Display raw RGB data as image using MFC

$
0
0
My project is that I have to get raw data from camera and display on screen using MFC. I saved data on buffer but I don't know how to display it directly. Any suggestion for my problem? Thank you very much.

Firstly, raw data format is captured like this: raw_image[width*height*3]= R G B R G B R G B R G B.. 1 pixel has 24 bits.

This is code fragment from my project which prepares BITMAPINFO structure to display graylevel 8 bpp image for StretchDIBits:

        BITMAPINFO* m_pBitmapInfo;   // class member
        m_pBitmapInfo = (BITMAPINFO*)new char[sizeof(BITMAPINFO) + sizeof(RGBQUAD)*256];
        m_pBitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        m_pBitmapInfo->bmiHeader.biWidth = IMAGE_SIZE;
        m_pBitmapInfo->bmiHeader.biHeight = -IMAGE_SIZE;  // if negative, image is mirrored     along y-axis
        m_pBitmapInfo->bmiHeader.biPlanes = 1;
        m_pBitmapInfo->bmiHeader.biBitCount = 8;
        m_pBitmapInfo->bmiHeader.biCompression  = BI_RGB;
        m_pBitmapInfo->bmiHeader.biSizeImage = 0; 
        m_pBitmapInfo->bmiHeader.biXPelsPerMeter = 0;
        m_pBitmapInfo->bmiHeader.biYPelsPerMeter = 0;
        m_pBitmapInfo->bmiHeader.biClrUsed = 256;
        m_pBitmapInfo->bmiHeader.biClrImportant = 0;
        for ( i = 0; i < 256; i++ )
        {
           m_pBitmapInfo->bmiColors[i].rgbBlue = i;
           m_pBitmapInfo->bmiColors[i].rgbGreen = i;
           m_pBitmapInfo->bmiColors[i].rgbRed = i;
           m_pBitmapInfo->bmiColors[i].rgbReserved = 0;
        }

        HDC hdc =::GetDC(m_picture.m_hWnd); // m_picture is variable of control picture with FRAME type
        write_bmp_file(raw_image, output, width_scale, height_scale);
   StretchDIBits(hdc,0,0,width,height,0,0,width,height,raw_image,m_pBitMapInfo,DIB_RGB_COLORS,SRCCOPY); // raw_file[widht*height*3]

But it doesn't show on control picture. How can I solve this problem?

Viewing all articles
Browse latest Browse all 15302

Trending Articles