?
Solved

Palette Problem? Color Gradient Looks Bad in 256C Mode

Posted on 1998-05-08
10
Medium Priority
?
248 Views
Last Modified: 2013-11-20
Currently, I am working on a project that requires me to draw a gradient-colored ellipse.  The input is the base color of the ellipse.  The logic is something like the following code fragment.

for (i=0; i<nGradient; i++)
{
    clrCurrent = m_clrGradient[i];
    m_pBrush->CreateSolidBrush(clrCurrent);
    m_pPen->CreatePen(PS_SOLID, 1, clrCurrent);
    pOldBrush = pDC->SelectObject(m_pBrush);
    pOldPen = pDC->SelectObject(m_pPen);
    pDC->Ellipse(rcCurrentRect);
    pDC->SelectObject(pOldBrush);
    pDC->SelectObject(pOldPen);
    m_pBrush.DeleteObject();
    m_pPen.DeleteObject();      
    rcCurrentRect.DeflateRect(CSize(x, y));
}

If the display mode was in 16-bit or 24-bit, the result looks great.  However, if it was in 8-bit (256 color), the result looks ugly.

I thought it might be the palette problem.  So, I tried to create a new palette and stick in all of the colors in m_clrGradient[].  Then selected the palette into the DC and had the DC to "Realize" it OK.  But, I still get the same ugly result.  

Basically, I have no anyother idea.  Is there any one who knows why?  

Thanks a lot.
0
Comment
Question by:hhan
[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
10 Comments
 

Author Comment

by:hhan
ID: 1308617
Edited text of question
0
 

Author Comment

by:hhan
ID: 1308618
Edited text of question
0
 

Expert Comment

by:dr_funfrock
ID: 1308619
 Your image might have more than 236 colors in it. If it does then windows tries to map the extra colors to a 'best' match.

 If you have less than 236 colors there may be other images in your app that have different colors. These colors ocmbined with your image may add up to more than 236 colors again causing a 'best' match.

 If you weant your image to look perfect you will have to lower the number of colors .. via photoshop or image composer

Bummer, I know :)

0
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!

 

Author Comment

by:hhan
ID: 1308620
Actually, I only have 32 levels of gradient.  Besides, it is not an image.  It is drawn dynamically.

Thank you anyway. :-)


0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1308621
Not only do you need to create a palette and select it into a DC, but you also need to handle the messages WM_QUERYNEWPALETTE, WM_PALETTECHANGED, and WM_PALETTEISCHANGING at your frame window level. One thing to look at is at http://www.codeguru.com/bitmap/bitmap_toc.shtml for a bunch of articles and code for palette.


0
 

Author Comment

by:hhan
ID: 1308622
Actually, it is an ActiveX control.  As you suggested, I have created handlers for each of the messages you mentioned above (using Class Wizard).  However, none of them has ever been reached at run time.

Can you give me more details how do I capture those messages in an ActiveX control (using MFC) and what should I do within those message handlers.

By the way, I have just realized that dithered colors are used to display the gradient.  I could see the Windows uses a mixture of dots for a given RGB color.  

0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1308623
If this is an activeX control, it will not work because those messages are only sent to the top level windows. This will be the main window for the application. Since you do not have any control over the main window, your control will not ever get those messages.

0
 

Author Comment

by:hhan
ID: 1308624
So, is there anyway that, from an ActiveX control, to change the color palette and use it for drawing???  
0
 

Author Comment

by:hhan
ID: 1308625
Thank you anyway.  I have just figured out the problem was the m_clrGradient[] stored the RGB from the RGB macro.  Instead of using RGB, I changed it to be PALETTERGB and it worked.

0
 

Accepted Solution

by:
shan1 earned 120 total points
ID: 1308626

Use PALETTERGB(r, g, b)
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

764 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