• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Converting a colored to grayscale

This topic is 5904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am programming a small game for my computer science course and I was wondering if either Direct X or Windows GDI has a function that will let me convert a colored image to a grayscale image.

##### Share on other sites
Sorry about the 2 posts. I hit the double click button on my mouse.

##### Share on other sites
Um... I only saw one post. Yet, I hope double clicking doesn''t post two... (Tooko runs from current thread and returns to last post) Well, that was exausting.
I wonder why I scare so many people away...

The past was unknown, the future was predicted.

##### Share on other sites
Why would you need a GDI function to do it? Just calculate the luminance of the pixels. Thats all a greyscale image is.

( Luminance = (R+G+B)/3 )

Death of one is a tragedy, death of a million is just a statistic.

##### Share on other sites
quote:
Original post by python_regious
( Luminance = (R+G+B)/3 )

I remember that you need different factors (that together summs to 1.0) for R and G and B, because one is more intense than other. But I cant remember those factors.

##### Share on other sites
luminance = 0.3*red + 0.59*green + 0.11*blue;

##### Share on other sites
quote:
luminance = 0.3*red + 0.59*green + 0.11*blue;

A long time ago, I made a test image with three regions exactly red, blue and green, and I used Photoshop to convert it to grayscale. From that test, I got the same formula, and it seems to work pretty well.

There is something else you should be careful with: Gamma correction. If you start mixing values and in the end you just send them to your VGA, your medium-intensity colors are going to be too dark.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015570
×