Large BMP

We developped a software that display's bitmap. It worked fine with small bitmap but the bitmap is not displayed when it is large (2K X 2K). We want to know how to handle a large bitmap using the WIN32 SDK (in c).
We just want to display the large bitmap on the screen
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That is a big bitmap, 16 meg if 32 bit color.  The graphics procedures in Windows 95 are still 16 bit so it is possbile that they are running out of memory with such a large bitmap.  but maybe not.

how are you trying to display the bitmap?  where does the problem occur.

Do you load the bitmap with LoadBitmap() or other procedure but get a NULL handle?  Or do you successfully load the or create the bitmap but are unable to BitBlt it to the screen?  Since the screen has less than 2KX2K pixels how are your tryign to display it?  Do you copy only a portion or are you shrinking it with StretchBlt()?
dduclosAuthor Commented:
Edited text of question
I can't help you without knowing more.  You still haven't answered most of my questions.  Do you know where the problem is occuring?  Is it when you load/create the bitmap or is it when you try to copy it to the screen?  How are you copying it to the screen?  etc.  there are other questions above.
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Are you sure that the bitmap has been read?  Do you use LoadImage() to read it in from a file (this is simplest), or do you read it yourself?

Use StretchBlt to draw the bitmap on the screen. This allows you to enlarge or shrink your bitmap (and also just copy a section of it, of course).

Can you post your code for drawing the bitmap?

Also, can you check what size bitmap is the largest you can successfully display?

You have not given us enough information to help you.  Both RONSLOW  and myself are asking you these questions because there is no way we (or anyone else) can help you without more information.
hmm, we do need more info, but from the comments...i can help u with an alternate sollution that's sure to work...well first this method is easy, it uses the win32 DrawDib functions...anyhow with this method u don't have to wory about color depth, screen size...etc. plus it's fairly fast...all u have to do is use the huge keyword...

m_pDIB = (BYTE huge *) new char[bmpfh.bfSize - nHeaderSize];
file.ReadHuge(m_pDIB, bmpfh.bfSize - nHeaderSize);
// that reads the file 32k at a time (if that's a problem)
if (((BITMAPINFOHEADER *) m_pDIB)->biSizeImage == 0)
pDib->biSizeImage = ((((pDib->biWidth*pDib->biBitCount)+31)&~31)>>3)*pDib->biHeight;
}  file.Close();

Somethin like'll have to let me know if this is how your approaching the problem
then i can give u more info...or an alternate solution...bmp's can reach 32K x 32K in size, or 2G x 2G in it's not the file limits, it's ur coding 4 sure...
                                                                                                        Pat b


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BTW: He wanted his answer in Win32 SDI in C, not MFC in C++

my bad, however you could do something similar, u still have the same types, and stucture for dib, you can load it the same way (i beleive) in 32k chunks, the only thing you'd have to do is probably use SetDIBitsToDevice() function to display it...this is an alternative method to LoadBitmap...but also alot more tedius cause you have to manually do all the file header analyzing...but not to bad to do...anyways with some more modifications u could make it so it's only WIN32 dependant...
                                                                                               Pat b

Here is an article from MSDN that shows how to use LoadImage to read in a bitamp AND how to use it to display a bitmap on the screen...

Microsoft Knowledge Base
How To Use LoadImage() to Read a BMP File
Last reviewed: November 18, 1996
Article ID: Q158898  
The information in this article applies to:
Microsoft Win32 Application Programming Interface (API) for Windows NT and Win95, version 4.00

The LoadImage() API can be used to load a bitmap from a BMP file. However, it does not return palette information. This article provides sample code and describes how to retrieve the palette information for the bitmap with LoadImage().

The following code uses the LoadImage() API to load the bitmap as a DIBSection, and then creates a palette from the DIBSection's color table. If no color table is present, a halftone palette is used:

   BOOL LoadBitmapFromBMPFile( LPTSTR szFileName, HBITMAP *phBitmap,
   HPALETTE *phPalette )
     BITMAP  bm;

     *phBitmap = NULL;
     *phPalette = NULL;

     // Use LoadImage() to get the image loaded into a DIBSection
     *phBitmap = LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,
     if( *phBitmap == NULL )
       return FALSE;

     // Get the color depth of the DIBSection
     GetObject(*phBitmap, sizeof(BITMAP), &bm );
     // If the DIBSection is 256 color or less, it has a color table
     if( ( bm.bmBitsPixel * bm.bmPlanes ) <= 8 )
       HDC           hMemDC;
       HBITMAP       hOldBitmap;
       RGBQUAD       rgb[256];
       LPLOGPALETTE  pLogPal;
       WORD          i;

       // Create a memory DC and select the DIBSection into it
       hMemDC = CreateCompatibleDC( NULL );
       hOldBitmap = SelectObject( hMemDC, *phBitmap );
       // Get the DIBSection's color table
       GetDIBColorTable( hMemDC, 0, 256, rgb );
       // Create a palette from the color table
       pLogPal = malloc( sizeof(LOGPALETTE) + (256*sizeof(PALETTEENTRY)) );
       pLogPal->palVersion = 0x300;
       pLogPal->palNumEntries = 256;
         pLogPal->palPalEntry[i].peRed = rgb[i].rgbRed;
         pLogPal->palPalEntry[i].peGreen = rgb[i].rgbGreen;
         pLogPal->palPalEntry[i].peBlue = rgb[i].rgbBlue;
         pLogPal->palPalEntry[i].peFlags = 0;
       *phPalette = CreatePalette( pLogPal );
       // Clean up
       free( pLogPal );
       SelectObject( hMemDC, hOldBitmap );
       DeleteDC( hMemDC );
     else   // It has no color table, so use a halftone palette
       HDC    hRefDC;

       hRefDC = GetDC( NULL );
       *phPalette = CreateHalftonePalette( hRefDC );
       ReleaseDC( NULL, hRefDC );
     return TRUE;

The following code demonstrates how to use the LoadBitmapFromBMPFile function:

    case WM_PAINT:
      PAINTSTRUCT   ps;
      HBITMAP       hBitmap, hOldBitmap;
      HPALETTE      hPalette, hOldPalette;
      HDC           hDC, hMemDC;
      BITMAP        bm;

     hDC = BeginPaint( hWnd, &ps );

     if( LoadBitmapFromBMPFile( zFileName, &hBitmap, &hPalette ) )
         GetObject( hBitmap, sizeof(BITMAP), &bm );
         hMemDC = CreateCompatibleDC( hDC );
         hOldBitmap = SelectObject( hMemDC, hBitmap );
         hOldPalette = SelectPalette( hDC, hPalette, FALSE );
         RealizePalette( hDC );

         BitBlt( hDC, 0, 0, bm.bmWidth, bm.bmHeight,
                 hMemDC, 0, 0, SRCCOPY );

         SelectObject( hMemDC, hOldBitmap );
         DeleteObject( hBitmap );
         SelectPalette( hDC, hOldPalette, FALSE );
         DeleteObject( hPalette );
     EndPaint( hWnd, &ps );

PS: If you find this sample more useful, don't forget to reject the proposed answer so that I can post this as an answer for you.

Another PS ... LoadBitmap will only read a bitmap from your resource, it won't read from a file.  That is why you either have to read the bitmap yourself, or use LoadImage to do it for you.  LoadImage sounds preferable because it is easier and less prone to programmer error (harder to get one line wrong than several)

note that the BitBlt call can be replaced by StretchBlt so you can zoom in/out and pan around your image.

Also, you would probably not want to load your image on every WM_PAINT .. just draw it, so move the loading code out of there to somewhere more applicable
It looks like some warmhearted doctors are treating a silent patient.
And the annoying thing is that all the effort will be for nothing if dduclos never reads it .. and I won't even get any points for my supplied code, because hotsextoy was the last to propose an answer and I cannot put my comments as answer until that one is rejected (or accepted or whatever).  So eventually hotsextoy will get the points due to EE auto-answer :-(

Told you so .. auto-grading is great .. but only when the best solution has been posted as an answer.  If not, then the 'auto' part means the answer is accepted regardless of whether it is the best solution proposed .. or even if it is correct!

Oh well .. them's the breaks I suppose.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.