I have 2 questions. 1 - I did succeed to see the message with replacing red by white. But I can't replace the red by white ? what I am doing wrong please ?

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

//switch red to white background
if (triple.rgbtRed == 0xff)
    triple.rgbtRed = 0xffffff;
if (triple.rgbtBlue == 0xff)
    triple.rgbtBlue = 0xffffff;
if (triple.rgbtGreen == 0xff)
    triple.rgbtGreen = 0xffffff;  

2- The final message is written is red on white. Please, can u explain me if in the code I changed the red to an other color for each RGB, how come the message appears in red ? tks

1 Answer 1

  • A value for Red, Green or Blue can have at most 0xff (255 in decimal), but you are assigning 0xffffff to all of R, G, B.
  • To check if pixel is red you have to check if red value is 0xff and green value is 0x00 and blue value is 0x00. red is rgb(255,0,0) and white is rgb(255,255,255)

The code should be something like:

if (triple.rgbtBlue == 0x00 && triple.rgbtGreen == 0x00 && triple.rgbtRed == 
0xff )  // if pixel value is red change it to white
    triple.rgbtRed = 0xff;
    triple.rgbtBlue = 0xff;
    triple.rgbtGreen = 0xff;

Hope you understood.


You must log in to answer this question.

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