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
  1. Home
  2. General Programming
  3. C#
  4. conversion problem!

conversion problem!

Scheduled Pinned Locked Moved C#
questionhelptutorial
8 Posts 4 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.
  • Y Offline
    Y Offline
    yassir hannoun
    wrote on last edited by
    #1

    how can i convert color form a hex format to a byte format? in other words how to convert from hex to argb thx

    C I 2 Replies Last reply
    0
    • Y yassir hannoun

      how can i convert color form a hex format to a byte format? in other words how to convert from hex to argb thx

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You mean if you have 0xFFFFFF, how to turn that into argb ? Something like this int color = 0xFFFFFF; byte alpha = (byte)((color && 0xFF000000) << 24); byte red = (byte)((color && 0xFF0000) << 16); byte green = (byte)((color && 0xFF00) << 8); byte blue = (byte)((color && 0xFF))); Something like that. Use the && to strip the other bits, and a bit shift to move it down to be just a byte.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      Y 1 Reply Last reply
      0
      • Y yassir hannoun

        how can i convert color form a hex format to a byte format? in other words how to convert from hex to argb thx

        I Offline
        I Offline
        Insincere Dave
        wrote on last edited by
        #3

        If you have it as a string use ColorTranslator.FromHtml.

        1 Reply Last reply
        0
        • C Christian Graus

          You mean if you have 0xFFFFFF, how to turn that into argb ? Something like this int color = 0xFFFFFF; byte alpha = (byte)((color && 0xFF000000) << 24); byte red = (byte)((color && 0xFF0000) << 16); byte green = (byte)((color && 0xFF00) << 8); byte blue = (byte)((color && 0xFF))); Something like that. Use the && to strip the other bits, and a bit shift to move it down to be just a byte.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          Y Offline
          Y Offline
          yassir hannoun
          wrote on last edited by
          #4

          so how can i get a value from a textbox and then convert it

          P C 2 Replies Last reply
          0
          • Y yassir hannoun

            so how can i get a value from a textbox and then convert it

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            Get the .Text string and then apply Christian's code to it.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            1 Reply Last reply
            0
            • Y yassir hannoun

              so how can i get a value from a textbox and then convert it

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Please, please, please buy a beginners book and read it.

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              Y 1 Reply Last reply
              0
              • C Christian Graus

                Please, please, please buy a beginners book and read it.

                Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                Y Offline
                Y Offline
                yassir hannoun
                wrote on last edited by
                #7

                well here is the way i got it to work int Color; Color = int.Parse(TextBox1.Text, NumberStyles.HexNumber);

                C 1 Reply Last reply
                0
                • Y yassir hannoun

                  well here is the way i got it to work int Color; Color = int.Parse(TextBox1.Text, NumberStyles.HexNumber);

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  OK, what this does is not what you asked for. This gives you a a single number, no color information at all.

                  Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  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