Displaying ".Raw" Images

I have a raw image that I have in an array, of 262144 (512x512)

I wish to display this image on the screen ? Can someone please provide source code on how to do this ?
The raw image is 8 bit greyscale.

I need it ASAP
jonsterAsked:
Who is Participating?
 
RONSLOWConnect With a Mentor Commented:
Even better, use StretchDIBits to do the work for you - again, you will need to set up a bitmap header that describes your bitmap data (width, height, bit-planes, colour palette etc).  Then you should be able to StretchDIBits from your data to a window on the screen directly (in OnDraw say).

0
 
MarkusLoiblCommented:
1.) Tranfer your image-format into the windows bitmap-format. The bitmap-format is well-described in the Windows-SDK. Then display the bitmap in your OnPaint()/OnDraw()-functions.
You find some code-fragments down here I copied from a project I am working on, only to show you the way (I use the code for first drawing in a bitmap and then displaying it, because this is much faster and there is no flickering if you just return TRUE  in your OnEraseBackground(); you have to tranform the code in order to fit to your problem).

or

2.) You can use the CDC::SetPixel-function for direct-drawing. You can mix this approach with the first-in-bitmap-drawing I mentioned in 1.). I can send you the complete first-in-bitmap-drawing by e-mail, if you send me your adress.

_______________________________________________________________

XWndAddOnBitmapPaint::XWndAddOnBitmapPaint()
{
      m_bIsCreated      = FALSE;
      m_pMemDC            = new CDC;
      m_pBitmap            = new CBitmap;
}

BOOL XWndAddOnBitmapPaint::CreateBitmap(const RECT& rect)
{
      CRect      rectClient, rectClientLP;

      if( m_bIsCreated )            return TRUE;
      
      m_bIsCreated = TRUE;

      m_SizeBitmap = CSize(abs( rect.right - rect.left ), abs( rect.bottom - rect.top ));

      // creates the memory device context and the bitmap
      if( m_pMemDC->GetSafeHdc() == NULL )
      {
            CClientDC dc(GetThis());
            m_pMemDC->CreateCompatibleDC(&dc);
            
            InflateBitmapSize(m_SizeBitmap);
      
            m_pBitmap->CreateCompatibleBitmap(&dc, m_SizeBitmap.cx, m_SizeBitmap.cy);
      }
      
      return TRUE;
}

void XWndAddOnBitmapPaint::OnPaint()
{
      CRect            rectClient,
                        rectClientLP,
                        updateRect;
      CBitmap            *newBitmap;
      CSize            oldSize;
      CBitmap            *pOldBitmap;

      CPaintDC dc(GetThis());
      if( GetThis()->IsKindOf(RUNTIME_CLASS(CView)) )
            ((CView*) GetThis())->OnPrepareDC(&dc);

      // falls Bitmap-Größe zu klein, neu festlegen
      GetThis()->GetClientRect(&rectClient); // in LP
      if( !m_bIsCreated )      CreateBitmap(rectClient);

      rectClientLP = rectClient;
      dc.DPtoLP(rectClientLP);
      oldSize = CSize(rectClientLP.right, rectClientLP.bottom);
      
      //
      //  hat nicht mehr Platz
      //
      if( InflateBitmapSize(oldSize) )      
      {
            try
            {
                  newBitmap = new CBitmap;
                  VERIFY(newBitmap);
            }
            catch(CMemoryException* e)
            {
                  e->Delete();
                  AfxMessageBox( _T("low memory in 'XWndAddOnBitmapPaint::OnPaint()' "), MB_OK | MB_ICONSTOP);
                  ASSERT_VALID(AfxGetMainWnd());
                  AfxGetMainWnd()->PostMessage(WM_CLOSE);
                  return;
            }
            
            newBitmap->CreateCompatibleBitmap(&dc, m_SizeBitmap.cx, m_SizeBitmap.cy);
            // alter Zeiger umbiegen, alte bmp löschen
            m_pBitmap->DeleteObject();
            delete m_pBitmap;
            m_pBitmap = newBitmap;
      }

      pOldBitmap = m_pMemDC->SelectObject(m_pBitmap);

      // updateRect festlegen
      dc.GetClipBox(&updateRect);
      m_pMemDC->SelectClipRgn(NULL);
      m_pMemDC->IntersectClipRect(&updateRect);

      // in Bitmap zeichnen
      m_pMemDC->FillSolidRect(0,0, m_SizeBitmap.cx, m_SizeBitmap.cy, RGB(192, 192, 192));
      OnDraw(m_pMemDC);

      // Bitmap darstellen
      dc.BitBlt(updateRect.left, updateRect.top,
                              updateRect.Width(), updateRect.Height(), m_pMemDC,
                              updateRect.left, updateRect.top, SRCCOPY);
      
      m_pMemDC->SelectObject(pOldBitmap);
}


0
 
jonsterAuthor Commented:
The mumble jumble of your code is very confusing....

All I want is
1. From an array (called buffer) of 512x512 (262144 bytes) greyscale.

2. Display the greyscale image on the screen when the function is called.

Cheers
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
MarkusLoiblCommented:
I don't really know what you want !
I told you a possible ways to do it (and gave you some code, ok, it doesn't fit but it just should show how to draw into a bitmap).
You can use CDC::SetPixel() to draw your greyscale into a DC, (the window or a bitmap).
Doesn't that satify you ??
If you need exact code, then post exact questions !
What do you mean by "Display the greyscale image on the screen when the function is called.".
0
 
MarkusLoiblCommented:
I don't really know what you want !
I told you a possible ways to do it (and gave you some code, ok, it doesn't fit but it just should show how to draw into a bitmap).
You can use CDC::SetPixel() to draw your greyscale into a DC, (the window or a bitmap).
Doesn't that satify you ??
If you need exact code, then post exact questions !
What do you mean by "Display the greyscale image on the screen when the function is called.".
0
 
jonsterAuthor Commented:
Sorry, admittably you are in the right, I didn't really say what I wanted

Ok....I have  an array : value[i]
where i is 0 to (hsize x vsize) and the respective values are the greyscaled values i.e. between 0-255

for (i = 0; i < hsize*vsize; i++)
     value[i] = (Real)buffer[i];


I want a function that somehow displays these pixel values onto the screen when the function is called ?

Is that all the information you require ?
0
 
jonsterAuthor Commented:
Can you elaborate on how to set up a bitmap header ?

Code if possible ?

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.