Large BMP

Posted on 1998-04-15
Last Modified: 2013-12-03
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
Question by:dduclos
  • 7
  • 3
  • 2
  • +2
LVL 22

Expert Comment

ID: 1412792
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()?

Author Comment

ID: 1412793
Edited text of question
LVL 22

Expert Comment

ID: 1412794
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.
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

LVL 10

Expert Comment

ID: 1412795
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?

LVL 22

Expert Comment

ID: 1412796
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.

Accepted Solution

hotsextoy earned 200 total points
ID: 1412797
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

LVL 10

Expert Comment

ID: 1412798
BTW: He wanted his answer in Win32 SDI in C, not MFC in C++


Expert Comment

ID: 1412799
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

LVL 10

Expert Comment

ID: 1412800
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.

LVL 10

Expert Comment

ID: 1412801
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)

LVL 10

Expert Comment

ID: 1412802
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
LVL 23

Expert Comment

ID: 1412803
It looks like some warmhearted doctors are treating a silent patient.
LVL 10

Expert Comment

ID: 1412804
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 :-(

LVL 10

Expert Comment

ID: 1412805
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.


Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How Does Quick Books store date / time? 3 97
Example of WebAPI 7 33
Is COM supported from Apache 1 52
Windows ICD FFU Issue 4 35
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

805 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