Take the 2-minute tour ×

So I'm using a variation of something I found on the web to convert images to gray scale. I'd like to be able to "fade to gray" I.e. fade the color incrementally so I can go from full colour through partially coloured to pure gray.

public static ColorMatrix ColorMatrixForGrayScale = new ColorMatrix(new[] {

    public static Bitmap MakeGrayscale(Image original, int percent = 100)
        ColorMatrix matrix = GetMatrix(percent); // returns a variation of the above.

        //create a blank bitmap the same size as original
        var newBitmap = new Bitmap(original.Width, original.Height);

        //get a graphics object from the new image
        var g = System.Drawing.Graphics.FromImage(newBitmap);

        //create some image attributes
        var attributes = new ImageAttributes();

        //set the color matrix attribute

        //draw the original image on the new image
        //using the grayscale color matrix

        //dispose the Graphics object
        return newBitmap;

So the question is two parts. First, can I use a matrix for that? If yes, what do I vary, if no, what is a workable approach? I'm thinking of creating full gray scale and then merging it with the colour image (some how).


edit: Original source Switch on the code

share|improve this question
What do you mean by partial gray scale? On area being colored and the rest gray scale (that's called colorkey)? Not sure what you mean –  Sascha Jun 9 '12 at 20:03
Sorry, I didn't make that clear. Imagine a picture that is just all red. Convert it to gray scale and it would be all gray. Partially convert it and the colour would be somewhere between red and gray. –  Ian Jun 9 '12 at 20:05
I think like reducing the saturation while keeping light and hue the same? –  Ian Jun 9 '12 at 20:06
For saturation look at codeproject.com/Tips/78995/… –  Sascha Jun 9 '12 at 20:08
Perfect, pop it in an answer and I'll vote for it :) –  Ian Jun 9 '12 at 20:46

1 Answer 1

up vote 1 down vote accepted

To change the saturation there is an interesting article at http://www.codeproject.com/Tips/78995/Image-colour-manipulation-with-ColorMatrix

share|improve this answer

Your Answer


