Solved

Displaying ".Raw" Images

Posted on 1997-05-28
7
360 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 200 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
has22 challenge 11 104
abstract class with all non abstract mentods 6 80
How to convert MFC::CString to UTF8 wchar_t* 10 278
Problem to App source 6 71
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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