Thread: Need help with adding various colors to BMP File

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    28

    Need help with adding various colors to BMP File

    Ok, so I have a program that essentially takes in a bmp file, and outputs a output bmp. Now, if I did nothing to the input file, then essentially the same file will write as the output file. I have the capability of altering the color of the out file to a single color.But for the life of me,I cant figure out how to add multiples color to the output file. So say for example, if I had a input file that contains the colors red and white. How would I alter it(the input file) to change the color format to say, blue and white. Here is the code I have:

    Code:
       for (int j = 0; j < bi.biWidth; j++)
            {
                // temporary storage
              RGBTRIPLE triple;// RGBTRIPLE is a struct 
              BYTE temp; //BYTE is a struct that is made up of uint8_t.
               
                 char temp2[7]="ff";
             
                
                fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
              
               
                 temp= (BYTE)temp2; 
                 triple.rgbtGreen=temp;
                 triple.rgbtRed=temp;
                 triple.rgbtBlue=00;
               
               
                fwrite(&triple, sizeof(RGBTRIPLE), 1,outptr);
               
            }
    Any help would be greatly apprecitaed. Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Perhaps
    triple.rgbtGreen=0xff;
    triple.rgbtRed=0xff;
    triple.rgbtBlue=0x00;

    Instead of all that mucking about with strings.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    28
    I see. But what if I want the file to have a mixture of white included with that yellow. How would I go about implementing that.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    You could use one of the many HTML color charts, for example

    HTML Color Chart

    Look at the hex codes in the HTML color you like and use those values as your red, green, and blue parts

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    28
    Quote Originally Posted by c99tutorial View Post
    You could use one of the many HTML color charts, for example

    HTML Color Chart

    Look at the hex codes in the HTML color you like and use those values as your red, green, and blue parts
    Cool. So with my code, if I wanted to generate a mixture of white and red, I would just pick a color that does that for me? When glancing at a scanline of pixels on a bmp, I see both red and white hex codes being used. How is that implemented?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Pick a colour
    Say
    Deepskyblue #00BFFF

    Take the appropriate pair of hexadecimal digits.
    Put 0x in front of them in your C code.
    Assign the appropriate members of your colour triple struct.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    28
    got it, thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to increase Colors(More Colors)?
    By shansajid in forum C Programming
    Replies: 5
    Last Post: 01-07-2013, 09:50 AM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. adding data to the middle of a file from another file
    By xixpsychoxix in forum C Programming
    Replies: 9
    Last Post: 09-07-2006, 11:00 AM
  4. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  5. Adding to a file
    By Puzzled in forum C++ Programming
    Replies: 3
    Last Post: 06-05-2003, 07:22 AM