?
Solved

Display two 256 color images in one view.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

839 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