When I run my whodunit on clue.bmp, I get the same red image as clue.bmp. Any advice on how to get rid of the red? Thanks in advance!

Here is the code where I attempt to turn the red white:

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
    // iterate over pixels in scanline
    for (int j = 0; j < bi.biWidth; j++)
        // temporary storage
        RGBTRIPLE triple;

        if (triple.rgbtBlue == 0x00 && triple.rgbtGreen == 0x00 && triple.rgbtRed == 0xff)
            triple.rgbtBlue = 0xff ;
            triple.rgbtGreen = 0xff ;
            triple.rgbtRed = 0xff ;

        // read RGB triple from infile
        fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

        // write RGB triple to outfile
        fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

2 Answers 2


I'm not going to spoil the answer for you, but I'll share the line of reasoning that helped me to "get the red out" of the image.

Think about this. The hexadecimal RGB representation of black is #000000 and the hexadecimal RGB representation of white is #ffffff. If I make the red value higher than the green and blue values, the pixel will get redder until eventually reaching pure red at #ff0000. Now answer me this: if you wanted your clue.bmp image to appear in 256 shades of gray, what values should you assign for the green and blue?

  • I am still confused. I tried making green and blue both FF, but that didn't work. No matter what I change them to the result is the same. Is there something wrong with the location / implementation of my code? Thanks! Jul 28, 2016 at 20:14
  • 2
    You might want to read what W3Schools has to say about Hexadecimal Shades of Gray. I can't give you a much more direct clue than that. If this helps you figure it out, please upvote my answer! Jul 28, 2016 at 20:35
  • I got it! Thanks! Jul 28, 2016 at 20:40
  • Ha! Glad I could help! Jul 28, 2016 at 20:41

It turned out that I needed to change the location of my code. I had to have the fread command before it! Thank anyway for the help!

  • Whoops! I didn't even see that -- but it should have been obvious! Jul 31, 2016 at 1:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .