Results 1 to 13 of 13

Thread: How can I find the 32 bit number of a color?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    29

    How can I find the 32 bit number of a color?

    For example, black is 0, how can I find out what number other colors are?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How can I find the 32 bit number of a color?

    The Color structure has a ToArgb method that returns an Integer, i.e. 32-bit number. You can use the BitConverter class to break that into its alpha, red, green and blue components if desired. There is also a FromArgb method that will accept a single 32-bit value or four 8-bit values.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    29

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by jmcilhinney View Post
    The Color structure has a ToArgb method that returns an Integer, i.e. 32-bit number. You can use the BitConverter class to break that into its alpha, red, green and blue components if desired. There is also a FromArgb method that will accept a single 32-bit value or four 8-bit values.
    Now, can you repeat that to someone that's retarded?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How can I find the 32 bit number of a color?

    I don't consider forums to be the place to learn the basics of programming. There are plenty of beginner tutorials for that. When people post questions on forums I assume that they have already done the work required to cover the basics so, if I say "set this property", "call this method" or "handle this event", they know how set a property, call a method or handle an event. If you don't know how to do those things then I suggest that you start with a beginners tutorial and cover the basics first. Here's a good one:

    http://www.homeandlearn.co.uk/net/vbnet.html

    Assuming you know how to do those basics things, either now or after reading that, you can use the advice I've already provided, which is basically to call the ToArgb method on your Color value. That's how you get a 32-bit number that represents a colour. If that doesn't cover your particular situation then you will need to explain your particular situation, so that we can provide advice specific to that situation.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by jmcilhinney View Post
    The Color structure has a ToArgb method that returns an Integer, i.e. 32-bit number. You can use the BitConverter class to break that into its alpha, red, green and blue components if desired. There is also a FromArgb method that will accept a single 32-bit value or four 8-bit values.
    The Color structure also has A, R, G, + B properties that represent the alpha, red, green and blue components

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    29

    Re: How can I find the 32 bit number of a color?

    I did a google search and followed this tutorial
    http://www.youtube.com/watch?v=7lO0JMWwa2Q

    I still don't know how to find the 32bit value of a color i put my mouse over =/

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by Dgameman1 View Post
    I did a google search and followed this tutorial
    http://www.youtube.com/watch?v=7lO0JMWwa2Q

    I still don't know how to find the 32bit value of a color i put my mouse over =/
    You didn't say anything about putting your mouse over anything in any previous post. We can't read minds so you have to provide us with all the relevant information. I've explained how to get a 32-bit numerical representation of a Color value. I had no idea that that Color value had to be created based on where your mouse pointer was currently located. I could suggest one way that I know would work but I doubt that it's the most efficient, so I'll leave it up to someone else.

    Please provide a FULL and CLEAR description of EXACTLY what you want in future and you'll save us and yourself a lot of time.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    29

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by jmcilhinney View Post
    You didn't say anything about putting your mouse over anything in any previous post. We can't read minds so you have to provide us with all the relevant information. I've explained how to get a 32-bit numerical representation of a Color value. I had no idea that that Color value had to be created based on where your mouse pointer was currently located. I could suggest one way that I know would work but I doubt that it's the most efficient, so I'll leave it up to someone else.

    Please provide a FULL and CLEAR description of EXACTLY what you want in future and you'll save us and yourself a lot of time.
    Sorry about that.
    Could you tell me the way you know? =D

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How can I find the 32 bit number of a color?

    1. Use the Screen class to get the size of the desktop on the primary screen.
    2. Create a Bitmap of that size.
    3. Create a Graphics object from the Bitmap.
    4. Call CopyFromScreen to copy the desktop to the Bitmap.
    5. Use the Cursor class to get the current mouse pointer location.
    6. Call GetPixel on the Bitmap to get the Color at that location.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by jmcilhinney View Post
    1. Use the Screen class to get the size of the desktop on the primary screen.
    Couldn't you just get the pixel under the mouse pointer, maybe something like...

    Code:
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Using bmp As New Bitmap(1, 1)
            Using g As Graphics = Graphics.FromImage(bmp)
                g.CopyFromScreen(MousePosition, Point.Empty, bmp.Size)
                Dim c As Color = bmp.GetPixel(0, 0)
                Debug.WriteLine(c)
            End Using
        End Using
    End Sub

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    29

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by Edgemeal View Post
    Couldn't you just get the pixel under the mouse pointer, maybe something like...

    Code:
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Using bmp As New Bitmap(1, 1)
            Using g As Graphics = Graphics.FromImage(bmp)
                g.CopyFromScreen(MousePosition, Point.Empty, bmp.Size)
                Dim c As Color = bmp.GetPixel(0, 0)
                Debug.WriteLine(c)
            End Using
        End Using
    End Sub
    I don't see where it says the color tho =/

  12. #12
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by Dgameman1 View Post
    I don't see where it says the color tho =/
    I'm not familar with using Color in .NET, maybe use c.ToArgb ?
    I've seen people ask how to get a color value in hex and the answer was something like,...

    Me.Text = c.ToArgb.ToString("X")

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Apr 2011
    Posts
    29

    Re: How can I find the 32 bit number of a color?

    Quote Originally Posted by Edgemeal View Post
    I'm not familar with using Color in .NET, maybe use c.ToArgb ?
    I've seen people ask how to get a color value in hex and the answer was something like,...

    Me.Text = c.ToArgb.ToString("X")
    Ok, it worked and the number it gave me was
    FFD4D0C8

    Now, What is a code where when I press button5, the mouse looks for a color in a certain area, then clicks that color and when it presses that color is goes and finds a different color in a different area and then clicks that color. How can I do that?

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