?
Solved

Displaying ".Raw" Images

Posted on 1997-05-28
7
Medium Priority
?
373 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:jonster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:MarkusLoibl
ID: 1301867
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
 

Author Comment

by:jonster
ID: 1301868
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
 
LVL 1

Expert Comment

by:MarkusLoibl
ID: 1301869
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:MarkusLoibl
ID: 1301870
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
 

Author Comment

by:jonster
ID: 1301871
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
 
LVL 10

Accepted Solution

by:
RONSLOW earned 400 total points
ID: 1301872
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
 

Author Comment

by:jonster
ID: 1301873
Can you elaborate on how to set up a bitmap header ?

Code if possible ?

Cheers
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question