Solved

Large BMP

Posted on 1998-04-15
14
1,230 Views
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
0
Comment
Question by:dduclos
  • 7
  • 3
  • 2
  • +2
14 Comments
 
LVL 22

Expert Comment

by:nietod
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()?
0
 

Author Comment

by:dduclos
ID: 1412793
Edited text of question
0
 
LVL 22

Expert Comment

by:nietod
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.
0
 
LVL 10

Expert Comment

by:RONSLOW
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?

0
 
LVL 22

Expert Comment

by:nietod
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.
0
 
LVL 1

Accepted Solution

by:
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)
{ BITMAPINFOHEADER huge * pDib = (BITMAPINFOHEADER * huge) m_pDIB;
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

0
 
LVL 10

Expert Comment

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

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Expert Comment

by:hotsextoy
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

0
 
LVL 10

Expert Comment

by:RONSLOW
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


SUMMARY
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().

MORE INFORMATION
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,
                 LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
     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;
       for(i=0;i<256;i++)
       {
         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 );
   }
   break;

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.

0
 
LVL 10

Expert Comment

by:RONSLOW
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)

0
 
LVL 10

Expert Comment

by:RONSLOW
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
0
 
LVL 23

Expert Comment

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

Expert Comment

by:RONSLOW
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 :-(

0
 
LVL 10

Expert Comment

by:RONSLOW
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.

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

21 Experts available now in Live!

Get 1:1 Help Now