标题:API getpixel 的用法问题
只看楼主
dafeixia88
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2010-2-23
 问题点数:0 回复次数:4 
API getpixel 的用法问题
各位精英,小弟最近用API中的getpixel 想获取屏幕上某一点像素,结果是据点有结果全-1,心情十分沉重,万望知道的指点一二,十分感谢,原代码如下:
 Private Declare Function getpixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Integer, ByVal y As Integer) As Integer
 Public Shared Function gaincolor(ByVal p As Point, ByVal aaa As IntPtr) As Long

        'Dim bbb As Color
        Dim ccc As Long
        Dim ddd As Long
        ddd = GetWindowDC(aaa)
        ccc = getpixel(ddd, p.X, p.Y),此处ccc总是返回-1   
        SetPixel(ddd, p.X, p.Y, 300),此处好像没有执行结果
        Return ccc
    End Function

上述函数返回值总是-1
搜索更多相关主题的帖子: 用法 getpixel API 
2010-02-25 10:02
dafeixia88
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2010-2-23
得分:0 
Public Shared Function gaincolor(ByVal p As Point, ByVal aaa As IntPtr) As Int32
        Dim ccc As IntPtr
        Dim ddd As Int32
        ccc = GetDC(0)
        ddd = getpixel(ccc, 200, 100)
        ReleaseDC(0, ccc)
        Return ddd
    End Function
改进代码,还是不对,每次获得数值不一样
2010-02-25 16:47
dafeixia88
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2010-2-23
得分:0 
有人能给我一个最简单的例子吗?比如取屏幕上200,200像素处点的颜色
我用的VB2005,谢谢!!!
2010-02-25 17:46
dafeixia88
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2010-2-23
得分:0 
算了,不用它了,改用截屏取色吧,已经完成,谢谢大家
2010-02-26 20:57
a413459164
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-3-19
得分:0 
又不用那么灰心,截屏太麻烦了,,,

Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Intptr, ByVal x As Integer, ByVal y As Integer) As Interger  '注意 .net 中句柄类型都改成                                                        Intptr      /.............  
 
  Public struce POINTAPI  '这个改改,(struce)
        x As Long
        y As Long
End Type
Public Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (Byref lpPoint As POINTAPI) As bool   '注意这里的byref一定要传址...

Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As intptr) As intptr
dim p as new POINTAPI
getCursorPos(p)

GetPixel(GetDC(Intptr.zero),p.x,p.y)

   我是用C#的,这里的代码可能有些出入,自己改改
2010-03-19 21:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-298087-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.997450 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved