Results 1 to 9 of 9

Thread: GetPixel Problem

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    How do I extract Red, Green and Blue values from the value that is returned by GetPixel

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    'red value
    dim retval as long
    retval = GetRValue(GetPixel(HDC,x,y))
    'green & blue
    GetBValue & GetGValue
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Member
    Join Date
    Jul 1999
    Posts
    42
    Sorry but GetRValue() if a VC++ function not a VB function

  4. #4
    Member
    Join Date
    Jul 1999
    Posts
    42
    ' Test routine to substract color components
    Private Sub Command1_Click()
    Dim Red As Long, Green As Long, Blue As Long
    Dim Color As Long

    ' Create a color to test the sub
    Color = RGB(150, 175, 200)

    ' Extract color components
    Red = Color And &HFF
    Green = (Color \ 256) And &HFF
    Blue = (Color \ 256 \ 256) And &HFF

    ' Show
    MsgBox "Red=" & Red ' Must be 150
    MsgBox "Green=" & Green ' Must be 175
    MsgBox "Blue=" & Blue ' Must be 200


    End Sub

  5. #5
    Guest
    Code:
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        lColor = GetPixel(Picture1.hdc, X, Y)
        
        'Get Red, Green and Blue
        lRed = lColor Mod &H100
        lGreen = Int(lColor / &H100) Mod &H100
        lBlue = Int(lColor / &H10000) Mod &H100
        
    End Sub

  6. #6
    Member
    Join Date
    Jul 1999
    Posts
    42
    A regular VB form has Point(x,y) methode for setting/getting a pixel, You don't need the GetPixel() function from the API.
    Note: the GetPixel() API function's default mapping mode is in pixels and de default VB mapping mode is Twips.

  7. #7
    Guest
    You forgot to mention how much slower Point and PSet are compared to GetPixel and SetPixel.

  8. #8
    Member
    Join Date
    Jul 1999
    Posts
    42
    Your right, SetPixel() if about 50% faster then PSet () and GetPixel is about 70% faster then Point()

  9. #9
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    SetPixelV is even faster than SetPixel because it does not return the color the pixel is set to.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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