Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need to convert COLORREF to COLOR16

Need to convert COLORREF to COLOR16

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CoffeeAddict19
    wrote on last edited by
    #1

    I need to convert a COLORREF value to 3 COLOR16 (hex) values. I'm trying to fill out this structure:

    typedef struct _TRIVERTEX {
      LONG        x;
      Long        y;
      COLOR16     Red;
      COLOR16     Green;
      COLOR16     Blue;
      COLOR16     Alpha;
    }TRIVERTEX, *PTRIVERTEX;
    

    GetRValue, GetGValue, and GetBValue will give me color intensity integers, but those need to be converted to hex values. So to be more precise I need to convert from an integer to a COLOR16 hex value. Anyone got ideas?

    M M 2 Replies Last reply
    0
    • C CoffeeAddict19

      I need to convert a COLORREF value to 3 COLOR16 (hex) values. I'm trying to fill out this structure:

      typedef struct _TRIVERTEX {
        LONG        x;
        Long        y;
        COLOR16     Red;
        COLOR16     Green;
        COLOR16     Blue;
        COLOR16     Alpha;
      }TRIVERTEX, *PTRIVERTEX;
      

      GetRValue, GetGValue, and GetBValue will give me color intensity integers, but those need to be converted to hex values. So to be more precise I need to convert from an integer to a COLOR16 hex value. Anyone got ideas?

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      From the docs:

      The color information of each channel is specified as a value from 0x0000 to 0xff00.

      So you can take the one-byte value from the COLORREF and multiply by 256.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      C 1 Reply Last reply
      0
      • M Michael Dunn

        From the docs:

        The color information of each channel is specified as a value from 0x0000 to 0xff00.

        So you can take the one-byte value from the COLORREF and multiply by 256.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        C Offline
        C Offline
        CoffeeAddict19
        wrote on last edited by
        #3

        How do I take the 1 byte value from it?

        M 1 Reply Last reply
        0
        • C CoffeeAddict19

          How do I take the 1 byte value from it?

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          It's the value returned by GetXValue:

          COLORREF cr = RGB(64,128,196); // the original COLORREF
          BYTE red = GetRValue(cr); // the red value in the range 0-255
          COLOR16 red16 = red * 256; // multiply to convert it to the range of COLOR16

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          C 1 Reply Last reply
          0
          • M Michael Dunn

            It's the value returned by GetXValue:

            COLORREF cr = RGB(64,128,196); // the original COLORREF
            BYTE red = GetRValue(cr); // the red value in the range 0-255
            COLOR16 red16 = red * 256; // multiply to convert it to the range of COLOR16

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

            C Offline
            C Offline
            CoffeeAddict19
            wrote on last edited by
            #5

            Thanks.

            1 Reply Last reply
            0
            • C CoffeeAddict19

              I need to convert a COLORREF value to 3 COLOR16 (hex) values. I'm trying to fill out this structure:

              typedef struct _TRIVERTEX {
                LONG        x;
                Long        y;
                COLOR16     Red;
                COLOR16     Green;
                COLOR16     Blue;
                COLOR16     Alpha;
              }TRIVERTEX, *PTRIVERTEX;
              

              GetRValue, GetGValue, and GetBValue will give me color intensity integers, but those need to be converted to hex values. So to be more precise I need to convert from an integer to a COLOR16 hex value. Anyone got ideas?

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              COLORREF colorref = RGB(0x01,0x02,0x03); TRIVERTEX TriVertex; TriVertex.Red = (COLOR16)GetRValue(colorref) << 8; TriVertex.Green = (COLOR16)GetGValue(colorref) << 8; TriVertex.Blue = (COLOR16)GetBValue(colorref) << 8;

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups