-
The GetPixel api returns a RGB value of a certain pixel at a certain point but it gives it in a single value (i.e. it doesn't give you the individual RGB values as in R,G,B) Is there anyway of discovering the individual RGB values from the single value passed back by this API? Is there maybe any other way of getting the R,G,B value of a pixel?
This is really making me stand on my head so if somone can help me, I would be very appreciative.
-
Hmmm....
I don't remember all the GetPixel stuff but I think you could try and make a sub that reads all three RGB values and returns them or something. Once again, I don't know all the specifics of GetPixel so I'm not sure.
-
Functions
Hi,
These functions work fine for me.
OET
Private Function GetRed(colorVal As Long) As Integer
On Error Resume Next
GetRed = colorVal Mod 256
End Function
Private Function GetGreen(colorVal As Long) As Integer
On Error Resume Next
GetGreen = ((colorVal And &HFF00FF00) / 256&)
End Function
Private Function GetBlue(colorVal As Long) As Integer
On Error Resume Next
GetBlue = (colorVal And &HFF0000) / 65535 '(256& * 256&)
End Function
-
Code:
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Const CLR_INVALID = &HFFFF
Private Sub Command1_Click()
Dim MyColor As Long
Dim r As Byte
Dim g As Byte
Dim b As Byte
MyColor = GetPixel(Me.hdc, 10&, 10&)
If MyColor <> CLR_INVALID Then
r = MyColor And &HFF
g = (MyColor And &HFF00FF00) / &H100
b = (MyColor And &HFF0000) / &H10000
MsgBox "Red : " & r & vbCrLf & "Green : " & g & vbCrLf & "Blue : " & b
End If
End Sub
-
Thank you!!
Thank you soooo much for the Red Green & blue functions!!!
It is very very much appretiated!!
:D