Solved

Palette Problem? Color Gradient Looks Bad in 256C Mode

Posted on 1998-05-08
10
244 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 105
Looking for a specific application/software 2 114
Problem to open Excel file 15 174
Excel file not created as expected 7 79
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 …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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