Click here to Skip to main content
13,247,891 members (60,774 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 5 Nov 2009

Converting Color to Grayscale Using ATL::CImage

, 5 Nov 2009
Rate this:
Please Sign up or sign in to vote.
Demonstrates how the ATL::CImage class can be used to do color-to-grayscale conversion on images.


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

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
Mahdi Nejadsahbei2-Feb-14 0:07
memberMahdi Nejadsahbei2-Feb-14 0:07 
GeneralMy vote of 1 Pin
SteveScanlon9-Nov-09 10:24
memberSteveScanlon9-Nov-09 10:24 
GeneralMy vote of 2 Pin
Nick Gorlov9-Nov-09 1:36
memberNick Gorlov9-Nov-09 1:36 
General"Anyone who knows?" Pin
Axel Rietschin6-Nov-09 16:32
memberAxel Rietschin6-Nov-09 16:32 
GeneralSome comments [modified] Pin
mluri6-Nov-09 1:08
membermluri6-Nov-09 1:08 
GeneralRe: Some comments Pin
Darryl Bryk9-Aug-10 12:45
memberDarryl Bryk9-Aug-10 12: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 6 Nov 2009
Article Copyright 2009 by daily insider
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid