Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Large BMP

Posted on 1998-04-15
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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 400 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 this...you'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 pizels...so 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

636 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