|
-
Dec 22nd, 2001, 08:04 AM
#1
Thread Starter
Hyperactive Member
Color in a picture??
How can i get the color value from a picture (in pixel 14*54 for exemple) . Give me something please api, codesnippet anything.
-
Dec 22nd, 2001, 08:43 AM
#2
Get pixel retrieves the RGB value of the pixel at the (X,Y) coordinates in the current selected DC
Public Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Put your picture into a picture box, and you should be able to retrieve the color of any pixel with this code:
VB Code:
'Code to retrieve color
Public Const CLR_INVALID = &HFFFF
Public Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
public function getColor(byval hDC as long, byval X as long, byval Y as long) as long
lngColor = GetPixel(Hdc,X, Y)
if lngColor = CLR_INVALID then
Err.raise vbobjecterror + 25, "Coordinates out of boundaries"
else
getColor = lngColor
end if
end function
The HDC argument must be the hdc of the picturebox containing the picture (you can get this through: me.picture1.hdc, or whatever your picturebox is called).
Good luck
P.S.
I havn't tested this code, so there might be an error or two, but it should be pretty easy to sort them out.
-
Dec 22nd, 2001, 12:21 PM
#3
There is just one small problem with the code AIS_DK provided.
Using his code you can't pick a pixel which is colored yellow .
The CLR_INVALID is declared like this:
VB Code:
Private Const CLR_INVALID As Long = -1
'or
Private Const CLR_INVALID = &HFFFFFFFF
Best regards
-
Dec 22nd, 2001, 02:18 PM
#4
If you need to get the colour of pixels from an entire picture, you should use GetPixel. Otherwise, if all you need is to retrieve a point where the mouse is clicked, use VB's Point method.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|