初学: 如何提取屏幕上某一点的颜色信息?

FranklinBHU 教师  2003-12-18 05:04:18
例如:我想每隔1秒钟提取屏幕上(100,150)点的颜色信息,并与前一秒提取的颜色比较,看看是否是同一颜色?
如何用编程实现?
...全文
44 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
3661512 2003-12-18
参考一下别人怎么写的

取屏幕上的任意点的颜色
http://www.21code.com/codebase/?pos=down&id=418

不是很好下,建议在凌晨时多刷新试几次~
回复
online 2003-12-18
lblData是控建数组

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Sub Timer1_Timer()
Static lX As Long, lY As Long
On Local Error Resume Next
Dim P As POINTAPI, h As Long, hD As Long, r As Long
GetCursorPos P
If P.x = lX And P.y = lY Then Exit Sub
lX = P.x: lY = P.y
lblData(0).Caption = lX & "," & lY
h = WindowFromPoint(lX, lY)
lblData(1).Caption = h
hD = GetDC(h)
lblData(2).Caption = hD
ScreenToClient h, P
lblData(3).Caption = P.x & "," & P.y
r = GetPixel(hD, P.x, P.y)
If r = -1 Then
BitBlt Picture1.hdc, 0, 0, 1, 1, hD, P.x, P.y, vbSrcCopy
r = Picture1.Point(0, 0)
Else
Picture1.PSet (0, 0), r
End If
lblData(4).Caption = Hex$(r)
Picture1.BackColor = r
End Sub
回复
shwen 2003-12-18
用 API, GetDC(0) 可取得桌面得 hDC, GetPixel(hDC,X,y) 可取得对应坐标得颜色值
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告