?
Solved

Display two 256 color images in one view.

Posted on 2000-04-04
2
Medium Priority
?
172 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

Independent Software Vendors: 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

800 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