Solved

Display two 256 color images in one view.

Posted on 2000-04-04
2
167 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 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

724 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