PDA

Click to See Complete Forum and Search --> : GetPixel Problem


amitabh
Feb 11th, 2001, 01:23 AM
How do I extract Red, Green and Blue values from the value that is returned by GetPixel

Vlatko
Feb 11th, 2001, 06:41 AM
'red value
dim retval as long
retval = GetRValue(GetPixel(HDC,x,y))
'green & blue
GetBValue & GetGValue

Alfred
Feb 11th, 2001, 07:35 AM
Sorry but GetRValue() if a VC++ function not a VB function

Alfred
Feb 11th, 2001, 08:29 AM
' 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

Feb 11th, 2001, 09:52 AM
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

Alfred
Feb 11th, 2001, 10:33 AM
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.

Feb 11th, 2001, 10:44 AM
You forgot to mention how much slower Point and PSet are compared to GetPixel and SetPixel.

Alfred
Feb 11th, 2001, 12:54 PM
Your right, SetPixel() if about 50% faster then PSet () and GetPixel is about 70% faster then Point()

YoungBuck
Feb 11th, 2001, 05:01 PM
SetPixelV is even faster than SetPixel because it does not return the color the pixel is set to.