Solved

Displaying ".Raw" Images

Posted on 1997-05-28
7
346 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 62
Prevent this page from creating additional dialogs. 3 416
FizzBuzz challenge 9 77
Message not shown 5 34
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

26 Experts available now in Live!

Get 1:1 Help Now