Solved

Problems with bitmap and palette

Posted on 1998-09-08
1
281 Views
Last Modified: 2013-11-20
Hello,
I'm developing an application using MSVC++ 4.0 and MFC.  There should appear a picture when I run the application during some seconds.  I've scanned two pictures: one of 16 colors and other one of 256 colors for each display configuration.  
The code on the OnPaint routine is:
      CPaintDC dc(this);
      // get information about video mode
      int i, j, k;
      i = dc.GetDeviceCaps(BITSPIXEL);
      j = dc.GetDeviceCaps(PLANES);
      k = dc.GetDeviceCaps(NUMCOLORS);

      UINT resource;
      //deletes the resource used to initialize the CBitmap object
      m_bitmap.DeleteObject( );
      if ( (i==1) && (j==4) && (k==16) )
            resource = IDB_SPLASH16;      // 16 colors
      else
            resource = IDB_SPLASH;            // 256+ colors

      if (!m_bitmap.LoadBitmap(resource))
            return;

      CDC dcImage;
      if (!dcImage.CreateCompatibleDC(&dc))
            return;

      BITMAP bm;
      m_bitmap.GetBitmap(&bm);

      // Paint the image.
      CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
      dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
      dcImage.SelectObject(pOldBitmap);

I'm having problems with the picture shown.  The same picture that I visualize in the Photo Paint software looks different that when I visualize it as an open picture (it seems to loose colors).  I don't know if I should initialize the palette or change its order.  Is there any special configuration for the palette in order to make it work?  Anyway, is it a problem with the palette?  Else, is it an MFC problem or a graphical problem?
Thanks.
0
Comment
Question by:marakr
1 Comment
 
LVL 6

Accepted Solution

by:
snoegler earned 100 total points
ID: 1321902
You'd have to map the bitmap palette to the screen palette.
See online docs, 'CBitmap::LoadMappedBitmap'.

But i would suggest that you save your bitmap into a file and use the CImage class. The
palette handling & supported formats are really good to handle. And you can save space
by saving your bitmap as '.jpg' or '.gif', look at http://www.visualc.com (MFC, CImage)
A short example how to use:

CImage mySplash("splash.gif",CIMAGE_FORMAT_GIF);
CPalette *old=dc.SelectPalette(mySplash.GetPalette(),TRUE);
dc.RealizePalette();
mySplash.Draw(dc,x,y);
dc.SelectPalette(old);

That's all to display a palettized image.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Doc'in system (example?) BA 7 79
canBalance challenge 34 65
matchUp  challenge 9 72
Annoying "thing" blocks my view 4 51
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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