Solved

Palette Problem? Color Gradient Looks Bad in 256C Mode

Posted on 1998-05-08
10
242 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
Comment Utility
Edited text of question
0
 

Author Comment

by:hhan
Comment Utility
Edited text of question
0
 

Expert Comment

by:dr_funfrock
Comment Utility
 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
 

Author Comment

by:hhan
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:hhan
Comment Utility
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
Comment Utility
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
Comment Utility
So, is there anyway that, from an ActiveX control, to change the color palette and use it for drawing???  
0
 

Author Comment

by:hhan
Comment Utility
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
Comment Utility

Use PALETTERGB(r, g, b)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 57
List out all word 7 219
FizzBuzz challenge 9 71
Annoying "thing" blocks my view 4 49
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now