Platform SDK: Windows GDI
GetPixel
The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
COLORREF GetPixel(
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);
Parameters
hdc
[in] Handle to the device context.
nXPos
[in] Specifies the logical x-coordinate of the pixel to be examined.
nYPos
[in] Specifies the logical y-coordinate of the pixel to be examined.
Return Values
The return value is the RGB value of the pixel. If the pixel is outside of the current clipping region, the return value is CLR_INVALID.
Remarks
The pixel must be within the boundaries of the current clipping region.
Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device supports this function.
Requirements
Windows NT/2000 or later: Requires Windows NT 3.1 or later.
Windows 95/98/Me: Requires Windows 95 or later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Gdi32.lib.
代码如下:
Dim Color as long
Dim Red as long
Dim Green as Long
Dim Blue as long
Color =Picture1.Point(X, Y) 'X,Y坐标任意,只要在PICTUREBOX范围内
Red = Color and &HFF&
Greed = (Color\256) and &HFF&
Blue =Color\65536
顺便改成楼上的样子:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Color as long
Color =Picture1.Point(X, Y) '得到鼠标在picture控件上的X,Y坐标处颜色
picture1.tooltips="RED: " & (Color and &HFF) & ",Green:" & ((Color\256) and &HFF) & ",Blue:" & (Color\65536)
End Sub
使用了整除法,速度稍快一点点。
不知你是不是这个意思:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim color As Long
color = Picture1.Point(X, Y)
Picture1.ToolTipText = "color=" & color & ": red = " & color Mod 256 & ", green = " & ((color And &HFF00) / 256) Mod 256 & ", blue = " & (color And &HFF0000) / 65536
End Sub