Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Display two 256 color images in one view.

Posted on 2000-04-04
2
Medium Priority
?
177 Views
Last Modified: 2010-04-02
My problem is as follows. I am trying to display two gif images onto the same view. The problems arise when my graphics adapter is at 256 colors.

Inserting one image onto the view is o.k. The gif seems fine. When I add another image to the view the palette of image 1 get trampled over by the palette of image 2.

I can have a number of gifs onscreen and display each of them in turn by calling the following function :

BOOL CGifObject::DisplayGif(CDC* pCDC,int x,int y)
{
      if (!GIFLoaded) return FALSE;

      CPalette *oldpal;
          oldpal = pCDC->SelectPalette(&pal,TRUE);
      pCDC->RealizePalette();

      if (!hBMP)
      {
            hBMP = CreateDIBitmap(pCDC->m_hDC,(LPBITMAPINFOHEADER)&bmi->bmiHeader,CBM_INIT,
                                    (LPSTR)imageBits,(LPBITMAPINFO)bmi,DIB_RGB_COLORS);
      }
      
      if (Transparent)
        {
            DrawTransparentBitmap(pCDC->m_hDC, hBMP, x,y,
                        RGB(bmi->bmiColors[Transparent_Color].rgbRed,
                              bmi->bmiColors[Transparent_Color].rgbGreen,
                              bmi->bmiColors[Transparent_Color].rgbBlue));
      }
      else
      {
               CDC hdcTemp;
               hdcTemp.CreateCompatibleDC(pCDC);
               HBITMAP oldbmp = (HBITMAP)hdcTemp.SelectObject(hBMP);
            pCDC->BitBlt(x,y,cx,cy,&hdcTemp,xSrcOff,ySrcOff,SRCCOPY);
               hdcTemp.SelectObject(oldbmp);
               hdcTemp.DeleteDC();
               // destructor will delete DC
               
      }

      pCDC->SelectPalette(oldpal,TRUE);
      
      // 1. pCDC->RealizePalette();
      return TRUE;
}

At point 1. I tried to realize the old palette again but that didn't work. Even if only one image is displayed all the colors are screwed up.

I have encountered the same problem with bmp's. Here is the code for the DisplayBMP function :

BOOL CGifObject::DisplayBMP(CDC *pDC, int x, int y)
{    
      BITMAP                   bm;
      HBITMAP             hbmp;
      CBitmap                  *oldBmp;                        
      CDC                    memDC;
       
   
      //Test to see if image to display
      if (!BMPLoaded || pDC == NULL || m_hbits==NULL || m_hhdr==NULL)
      {
            return FALSE ;
      }
     
      CPalette *oldPal = NULL;

      if (m_cPal)            // we have a palette wrt the image
      {
            oldPal = pDC->SelectPalette(m_cPal,TRUE);
      }
      pDC->RealizePalette();

      m_pbits =  (char *)GlobalLock(m_hbits);    
      m_pHdr  =  (LPSTR)GlobalLock(m_hhdr);
      m_bmi   =  (BITMAPINFO*) m_pHdr;                   //Create a pointer to a  BITMAP info structure
      m_bmih  =  (BITMAPINFOHEADER *) m_pHdr;     //Create a pointer to a BITMAPINFOHEADER structure
      
      //Create a handle to the BMP
      hbmp = CreateDIBitmap(pDC->m_hDC, m_bmih, CBM_INIT, m_pbits, m_bmi, DIB_RGB_COLORS);                                 

      CBitmap *bmp = CBitmap::FromHandle(hbmp);
      
      
      GetObject(hbmp, sizeof(BITMAP), (LPVOID)&bm);
      memDC.CreateCompatibleDC(pDC);               
          
      oldBmp = (CBitmap*)memDC.SelectObject(bmp);
          
      //Draw bitmap on screen
      pDC->BitBlt(x,y,cx,cy,&memDC,xSrcOff,ySrcOff,SRCCOPY) ;
          
      //Reset device
      memDC.SelectObject(oldBmp);
          
      //Delete device
      memDC.DeleteDC();
          
      //Reset palette
      if (oldPal)
            pDC->SelectPalette(oldPal,TRUE);
          
      GlobalUnlock(m_hhdr);    
      GlobalUnlock(m_hbits);

      DeleteObject(hbmp);
         
      return 1;      
}

Is this the same problem???

Can somebody help me with the palette manager before I tear my hair out!!!

Thanx, Gordon.
0
Comment
Question by:jeffreyg
[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
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 400 total points
ID: 2685932
Since each individual image has its own palette, the quality of the images have to be compromised. You may create a halftone palette (CPalette::CreateHalftonePalette) and use it for all the images.

Check out the following GDI Technical Articles in the MSDN Library.

- Palette Awareness
- The Palette Manager: How and Why
- Using DIBs with Palettes
0
 

Author Comment

by:jeffreyg
ID: 2689201
Thanks, the HalftonePalette worked. I now can display multiple images with slight, but satisfactory degradation.

Gordon.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

636 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