-
Hello,
I notice that when I use the GetPixel API the result isn’t in the RGB format. I’m unfamiliar to whichever method it is using so would someone please notify me of any method of converting the result from the GetPixel API into RGB format? Thanks
-
This one has always confused me, I never quite worked out exactly what it was doing, it always seemed to me that some API Functions came back with RGB results in the correct form and some come back with the components mixed up (the red bit where the blue should be etc.
I think it's a bug rather than anything else
Try putting the results of pixels coloured gompletley red, blue or green into an RGBQUAD, se if you can work out which colour componentss are going where.
-
The GetPixel function returns a BGR encoded colour, in the format: 0xBBGGRR. So, use this to extract the items:
Code:
Private Type ColourRGB
lRed As Integer
lGreen As Integer
lBlue As Integer
End Type
Private Sub Form_Load()
Dim z As ColourRGB
z = ExtractColour(RGB(&HAA, &HBB, &HCC))
Debug.Print Hex(z.lRed)
Debug.Print Hex(z.lGreen)
Debug.Print Hex(z.lBlue)
End Sub
Private Function ExtractColour(lColour As Long) As ColourRGB
Dim tempC As ColourRGB
tempC.lBlue = (lColour \ &H10000) And &HFF
tempC.lGreen = (lColour \ &H100) And &HFF
tempC.lRed = lColour And &HFF
ExtractColour = tempC
End Function
-
Try this:
Code:
lColor = GetPixel(Picture1.hdc, 32, 32)
'Get Red, Green and Blue
lRed = lColor Mod &H100
lGreen = Int(lColor / &H100) Mod &H100
lBlue = Int(lColor / &H10000) Mod &H100
-
Just noticed...it's buggered the numbers. The &h10000 and such should be all together, with no spaces.
-
Thanks guys I'll give all the suggestions a try.
-
By the way, what does do? It's a command that I've never came across.
-
The Modulus operator divides two numbers and returns the remainder:
res is now 2 (since 20 / 6 = 18 r 2)
-
Oh yes, it the equivalent to % in C++. Thanks Parksie.