Solved

Displaying ".Raw" Images

Posted on 1997-05-28
7
333 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
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:MarkusLoibl
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Expert Comment

by:MarkusLoibl
Comment Utility
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
Comment Utility
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 200 total points
Comment Utility
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
Comment Utility
Can you elaborate on how to set up a bitmap header ?

Code if possible ?

Cheers
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now