CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2004
    Posts
    36

    Talking Convert COLORREF to RGB???

    Is there a way to convert a COLORREF value into the three RGB ints?

    -B

  2. #2
    Join Date
    Jun 2004
    Posts
    36

    Re: Convert COLORREF to RGB???

    well I just figured it out so if anybody's interested in the answer:

    COLORREF color;

    int iRed = GetRValue(color);
    int iBlue = GetBValue(color);
    int iGreen = GetGValue(color);


    Sometimes I amaze even myself.

  3. #3
    Join Date
    Oct 2000
    Location
    Ottawa, CANADA. (CNADA ROCKS!!)
    Posts
    1,895

    Re: Convert COLORREF to RGB???

    may be you can stop amazing yourself by reading the documentation!!
    and Canada rocks!! Peace bro.

  4. #4
    Join Date
    Jun 2004
    Posts
    36

    Re: Convert COLORREF to RGB???

    Yeah, but who has time for that.

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: Convert COLORREF to RGB???

    Reading the documentation?? That's cheating isn't it???
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    Join Date
    Jun 2004
    Posts
    36

    Re: Convert COLORREF to RGB???

    Quote Originally Posted by John E
    Reading the documentation?? That's cheating isn't it???

    I do believe it is. Isn't it an unwritten rule that programmers aren't supposed to read any documentation?

  7. #7
    Join Date
    Dec 2001
    Posts
    4

    Re: Convert COLORREF to RGB???

    Don't forget the following when looking at the different bytes of an integer:
    https://www.safaribooksonline.com/li...080/re286.html

    "RGB = red + (green * 256) + (blue * 65536)
    In other words, the individual color components are stored in the opposite order than you would expect. VB stores the red color component in the low- order byte of the integer’s low-order word, the green color in the high-order byte of the low-order word, and the blue color in the low-order byte of the high-order word."

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Convert COLORREF to RGB???

    Quote Originally Posted by David Carr View Post
    Don't forget the following when looking at the different bytes of an integer
    Are you sure OP needs your "tip" after 10.5 years?
    Victor Nijegorodov

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Convert COLORREF to RGB???

    Quote Originally Posted by David Carr View Post
    Don't forget the following when looking at the different bytes of an integer:
    https://www.safaribooksonline.com/li...080/re286.html

    "RGB = red + (green * 256) + (blue * 65536)
    In other words, the individual color components are stored in the opposite order than you would expect. VB stores the red color component in the low- order byte of the integer’s low-order word, the green color in the high-order byte of the low-order word, and the blue color in the low-order byte of the high-order word."
    actually, when converting individual component values back into a compound, you should use RGB() macro rather than doing it 'the hard way'.

    If you're talking about actual videomemory, then the above may not even be correct at all. There are videocards where there memorylayout is BGR, and I've even seen BRG
    typically there'll be either a padding byte or an alpha byte in there. though there are videocards that actually have 3 bytes per pixel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured