Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problems with bitmap and palette

Posted on 1998-09-08
1
Medium Priority
?
304 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased riskā€¦
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

926 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