各位高手:如何获得指定屏幕坐标处色彩,并对两处色彩进行比较模糊的对比,请举一例,谢谢!

mmxHwa 2003-12-03 10:07:53
各位高手:如何获得指定屏幕坐标处色彩,并对两处色彩进行比较模糊的对比,请举一例,谢谢!
...全文
116 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mmxHwa 2003-12-06
  • 打赏
  • 举报
回复
Well Done!
DemonXHunter 2003-12-05
  • 打赏
  • 举报
回复
其实不用那么复杂了,因为可以直接从屏幕DC读取象素,如下
dim clr as long
dim hdc as Long
hdc = GetDC(0)
clr=GetPixel(hdc,10,20)
FSoft 2003-12-04
  • 打赏
  • 举报
回复
point函数可以得到指定坐标的颜色
DemonXHunter 2003-12-04
  • 打赏
  • 举报
回复
用API
1.根据坐标x,y和函数WindowFromPoint 获取该坐标窗体
2.GetDC获取窗体hDC
3.ScreenToClient 获取该坐标在窗体中的相对坐标,cx,cy
4.用GetPixel(hdx,cx,cy)
DemonXHunter 2003-12-04
  • 打赏
  • 举报
回复
API函数声明自己用API函数浏览器找
dim pt as POINT
dim hWnd as LONG
dim hDC as LONG
dim color1 as long
pt.x=10:pt.y=200
hWnd=WindowFromPoint(pt)
hDC=GetDC(hWnd)
ScreenToClient(hWnd,pt)
color1=GetPixel(hDC,pt.x,pt.y)

mmxHwa 2003-12-04
  • 打赏
  • 举报
回复
Up + 在VB6 环境下
mmxHwa 2003-12-04
  • 打赏
  • 举报
回复
DemonXHunter (恶魔猎手) 的思路很好,但我现在自己一直调试不好,比如:
所求点在全屏的 (10,200 ) 处,
请给个完整的程序,谢谢!!
DemonXHunter 2003-12-04
  • 打赏
  • 举报
回复
point只能取VB自己窗体上的吧,是form对象或者picturebox对象的成员函数
mmxHwa 2003-12-03
  • 打赏
  • 举报
回复
再问一下:
如果所要的点不在本窗体内怎么办,比如另一个程序的窗体一直在其他窗体上面,而所要的点就在这个窗体上? 搞定了发满100分
DemonXHunter 2003-12-03
  • 打赏
  • 举报
回复
关于模糊比较,一下算法只是我个人的想法,并非正规算法,但我觉得比较可行
函数的返回值是一个平均色差,你可以设定返回值小于某个限定值,则为相同颜色。
function compareColor(color1 as long,color2 as long) as double
dim red1,green1,blue1,red2,green2,blue2
red1=color1 and &hff
geen1=cint(color1/&h100) and &hff
blue1=cint(color1/&h10000) and &hff

red2=color2 and &hff
geen2=cint(color2/&h100) and &hff
blue2=cint(color2/&h10000) and &hff
compareColor=(((red1-red2)^2+(green1-green2)^2+(blue1-blue2)^2)/3)^0.5
end function
northwolves 2003-12-03
  • 打赏
  • 举报
回复
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()
Me.ScaleMode = 3
PSet (100, 100), vbBlue 'SET COLOR
PSet (100, 50), vbBlue
PSet (50, 50), vbRed
MsgBox Hex(GetPixel(Me.hdc, 100, 100)) 'VBBLUE
MsgBox Hex(GetPixel(Me.hdc, 50, 50)) 'VBRED
MsgBox GetPixel(Me.hdc, 50, 50) = GetPixel(Me.hdc, 100, 50) 'DIFFERENT COLOR
MsgBox GetPixel(Me.hdc, 100, 100) = GetPixel(Me.hdc, 100, 50) ' SAME COLOR
End Sub
northwolves 2003-12-03
  • 打赏
  • 举报
回复
use API: GetPixel

VB声明
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
说明
在指定的设备场景中取得一个像素的RGB值
返回值
Long,指定点的RGB颜色。如指定的点位于设备场景的剪切区之外,则返回CLR_INVALID
参数表
参数 类型及说明
hdc Long,一个设备场景的句柄
x,y Long,逻辑坐标中要检查的点

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧