Solved

Problems with bitmap and palette

Posted on 1998-09-08
1
301 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
[X]
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
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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

630 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