Results 1 to 19 of 19

Thread: Colour Picker

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Colour Picker

    Is there a colour pciker control in VB?

    Need the output like FF00FF

    Thank You
    ILMV

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Colour Picker

    you can use the commondialog control to open a palette of colours

  3. #3

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Colour Picker

    I need to convert the code value from the colour dialog box, from 65280 (or whatever it might be) to VB hex like... &H00FFFFFF&

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Colour Picker

    You could simply use the Hex function. However Windows store the colors in this format: BBGGRR while you probably want them outputted as RRGGBB right?

  5. #5

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Colour Picker

    Im not sure, you know the codes used in VB like &H00FFFFFF&

    That is the code for white. but i dont know what parts are for red, green and blue!?

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Colour Picker

    As I said the format Windows is using is BBGGRR.

  7. #7

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Colour Picker

    I know that the colour format it BGR, blue greed red.

    how do i use the HEX function, with example if possible.

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Colour Picker

    I have written a component called RGBMixer that can do what you need. It shows a dialog box in which the user can select from 3 different palettes to select a color from. They can also mix the color together from the three sliders that represent the RGB colors. See the screen shot.

    Here's an example how you use it.
    VB Code:
    1. Dim color As RGBMixer.CRGBMixer
    2. Set color = New RGBMixer.CRGBMixer
    3.  
    4. With color
    5.     .Palette = eWebSafe
    6.     .Format = eVBHex
    7.     If .ShowDialog = eOK Then
    8.         MsgBox "The select format for the color value " & .color & _
    9.          " is " & .Value
    10.     End If
    11. End With
    The CRGBMixer class has 4 properties and 1 method. The properties are:
    • Color - The selected color in decimal format. (Read-Only)
    • Format - The format the user has selected. There are 11 different formats to pick from.
    • Palette - The palette that should be shown by default.
    • Value - String value that represents the selected color in the selected format (Read-Only).


    The only method is ShowDialog that returns either eOK or eCancel depending on which button the user has clicked in the dialog box.

    Attached Images Attached Images  
    Attached Files Attached Files

  9. #9

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Colour Picker

    Cheers joacim.

    Will check it out

  10. #10
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Colour Picker

    Try this as well, assuming you have an image in a Picturebox.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
    4.  
    5. Private Color As Long
    6.  
    7. Private Hex_Color As String
    8.  
    9. Private Sub Form_Activate()
    10.    
    11.     Picture1.ScaleMode = 3 'Required for GetPixel to work.
    12.  
    13. End Sub
    14.  
    15. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    16.  
    17.     Color = GetPixel(Picture1.hDC, X, Y)
    18.    
    19.     Hex_Color = Hex(Color)
    20.    
    21.     Label1.Caption = Color
    22.     Label2.Caption = Hex_Color
    23.  
    24. End Sub

  11. #11
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Colour Picker

    Quote Originally Posted by Joacim Andersson
    As I said the format Windows is using is BBGGRR.
    Could someone explain to me why Windows is stupid and uses BGR when everything else uses RGB?
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Colour Picker

    It's not so much that Windows is stupid but that the Intel processor architecture use little endian by default. This means that the low-order byte is stored in the memory with the lowest address.

  13. #13
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Colour Picker

    DirectX is BGR based too

  14. #14
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Colour Picker

    Well, DirectX is made for Windows so that doesn't surprise me. However some applications and file format might use big endian even if they exist for Windows.

    Photoshop for example is big endian, but then again Photoshop was first developed for Mac which use Motorola processors which use big endian. BMP and GIF are little endians so both these image formats store color information in BGR format in memory. JPEG on the other hand is big endian. Other image formats that use little endians are PCX and TGA.

    Some image formats like for example TIFF and XWD use both little and big endians. They then have identifiers encoded into the file which specify which of the formats that is used.

    WPG (WordPerfect Graphics Metafiles) are big endians even though WordPerfect was first written for PC's.

  15. #15
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Colour Picker

    Uhhh?

    What is big/little edian?
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  16. #16
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Colour Picker

    Quote Originally Posted by eyeRmonkey
    Uhhh?

    What is big/little edian?
    If you only said this in the CC section

    I believe that would be the High Integer and Low Integer values of something. It's also used in the QueryPerformanceCounter and QueryPerformanceFrequency API's

  17. #17
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Colour Picker

    And what would your CC response be? Use that lame "best programmer" thread to respond.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  18. #18
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Colour Picker

    Quote Originally Posted by eyeRmonkey
    Uhhh?

    What is big/little edian?
    Explanation of Big Endian and Little Endian Architecture .

    Big endian is the red end of a baboon

  19. #19
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Colour Picker

    Quote Originally Posted by eyeRmonkey
    And what would your CC response be? Use that lame "best programmer" thread to respond.
    I hope you like bananas

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