Solved

Problems with bitmap and palette

Posted on 1998-09-08
1
285 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

15 Experts available now in Live!

Get 1:1 Help Now