Click here to Skip to main content
15,213,956 members

Converting Color to Grayscale Using ATL::CImage

Rate this:
3.07 (7 votes)
Please Sign up or sign in to vote.
3.07 (7 votes)
5 Nov 2009CPOL
Demonstrates how the ATL::CImage class can be used to do color-to-grayscale conversion on images.
Image 1


This is just a simple MFC application that demonstrates how you can use the ATL::CImage class to do color-to-grayscale conversion.


Conversion is done by:

  1. obtaining the red, green, and blue values in each pixel's color information,
  2. adding together 30% of the red value, 59% of the green value, and 11% of the blue value,
  3. using the sum obtained in step 2 as the new red, green, and blue values.

Using the Code

There are two implementations for doing the conversion:

  • MakeGrayscale_Slow() --> simple but slow
  • MakeGrayscale_Fast() --> a little complicated but fast

Points of Interest

MakeGrayscale_Slow() and MakeGrayscale_Fast() produce different grayscales for the same color image. I have no idea why this happens. Anyone who knows?


  • 2009/11/06 - Uploaded this article


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

daily insider
Philippines Philippines
No Biography provided

Comments and Discussions

GeneralMy vote of 2 Pin
Mahdi Nejadsahebi1-Feb-14 23:07
MemberMahdi Nejadsahebi1-Feb-14 23:07 
GeneralMy vote of 1 Pin
SteveScanlon9-Nov-09 9:24
MemberSteveScanlon9-Nov-09 9:24 
GeneralMy vote of 2 Pin
Nick Gorlov9-Nov-09 0:36
MemberNick Gorlov9-Nov-09 0:36 
General"Anyone who knows?" Pin
Axel Rietschin6-Nov-09 15:32
professionalAxel Rietschin6-Nov-09 15:32 
GeneralSome comments [modified] Pin
mluri6-Nov-09 0:08
Membermluri6-Nov-09 0:08 
GeneralRe: Some comments Pin
Darryl Bryk9-Aug-10 11:45
MemberDarryl Bryk9-Aug-10 11:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 5 Nov 2009

Tagged as


9 bookmarked