dabian001 发表于 2007-5-28 17:10:57

帮我改一下

<p>Option Explicit</p><p>Private Type BITMAPINFOHEADER '40 bytes<br/>&nbsp;&nbsp;&nbsp; biSize As Long<br/>&nbsp;&nbsp;&nbsp; biWidth As Long<br/>&nbsp;&nbsp;&nbsp; biHeight As Long<br/>&nbsp;&nbsp;&nbsp; biPlanes As Integer<br/>&nbsp;&nbsp;&nbsp; biBitCount As Integer<br/>&nbsp;&nbsp;&nbsp; biCompression As Long<br/>&nbsp;&nbsp;&nbsp; biSizeImage As Long<br/>&nbsp;&nbsp;&nbsp; biXPelsPerMeter As Long<br/>&nbsp;&nbsp;&nbsp; biYPelsPerMeter As Long<br/>&nbsp;&nbsp;&nbsp; biClrUsed As Long<br/>&nbsp;&nbsp;&nbsp; biClrImportant As Long<br/>End Type<br/>Private Type RGBQUAD<br/>&nbsp;&nbsp;&nbsp; rgbBlue As Byte<br/>&nbsp;&nbsp;&nbsp; rgbGreen As Byte<br/>&nbsp;&nbsp;&nbsp; rgbRed As Byte<br/>&nbsp;&nbsp;&nbsp; rgbReserved As Byte<br/>End Type<br/>Private Type BITMAPINFO<br/>&nbsp;&nbsp;&nbsp; bmiHeader As BITMAPINFOHEADER<br/>&nbsp;&nbsp;&nbsp; bmiColors As RGBQUAD<br/>End Type</p><p>Private Const DIB_RGB_COLORS As Long = &amp;H0&amp;<br/>Private Const BI_RGB As Long = &amp;H0&amp;<br/>Private Const OBJ_BITMAP As Long = &amp;H7&amp;<br/>Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal nNumScans As Long, ByVal lpBits As Long, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long<br/>Declare Function GetCurrentObject Lib "gdi32" (ByVal Hdc As Long, ByVal uObjectType As Long) As Long<br/>Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)<br/>Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long<br/>Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal Hdc As Long) As Long</p><p>'===================================以上不用管他===============================</p><p></p><p><br/>'从左到右.从下往上 顺序<br/>Public Function FindColor(ByVal Hdc As Long, ByVal Width As Long, ByVal Height As Long,&nbsp;ByVal Find_Color As Long, ByRef PoX As Long, ByRef PoY As Long)</p><p><br/>Dim Bi As BITMAPINFO<br/>Dim LngCol As Long, hMap As Long, LenBuf As Long, R As Long<br/>Dim BmpBuf() As Byte<br/>Dim PX As Long, PY As Long</p><p>&nbsp;&nbsp;&nbsp; On Error GoTo ErrLine</p><p>&nbsp;&nbsp;&nbsp; Find_Color = (&amp;HFF And Find_Color) * &amp;H10000 + (&amp;HFF00&amp; And Find_Color) + _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (&amp;HFF0000 And Find_Color) / &amp;H10000</p><p>&nbsp;&nbsp;&nbsp; With Bi.bmiHeader<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biSize = Len(Bi.bmiHeader)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biWidth = Width<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biHeight = Height<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biPlanes = 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biBitCount = 24<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biCompression = BI_RGB<br/>&nbsp;&nbsp;&nbsp; End With</p><p>&nbsp;&nbsp;&nbsp; LenBuf = (Width) * (Height) * 3<br/>&nbsp;&nbsp;&nbsp; ReDim BmpBuf(LenBuf - 1)&nbsp;&nbsp;&nbsp; 'MsgBox bmpBuf(2359295)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; hMap = GetCurrentObject(Hdc, OBJ_BITMAP)<br/>&nbsp;&nbsp;&nbsp; GetDIBits Hdc, hMap, 0, Bi.bmiHeader.biHeight, VarPtr(BmpBuf(0)), Bi, DIB_RGB_COLORS</p><p>&nbsp;&nbsp;&nbsp; '从左到右.从下往上 顺序<br/>&nbsp;&nbsp;&nbsp; For PY = Height To 1 Step -1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For PX = 1 To Width<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CopyMemory LngCol, BmpBuf(R), 3</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LngCol = Find_Color Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PoX = PX - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PoY = PY - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Erase BmpBuf<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R = R + 3<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; Next</p><p>ErrLine:<br/>&nbsp;&nbsp;&nbsp; PoX = -1<br/>&nbsp;&nbsp;&nbsp; PoY = -1<br/>&nbsp;&nbsp;&nbsp; Erase BmpBuf<br/>&nbsp;&nbsp;&nbsp; 'MsgBox "错误号:" &amp; Err.Number &amp; "错误信息:" &amp; Err.Description<br/>End Function<br/></p><p></p><p>'===============================================================</p><p><font color="#ff0000">帮我改成下面的过程........................谢谢</font></p><p><font color="#0000ff">Call FindColor(区域左边:整数,&nbsp;&nbsp; 区域上边:整数,&nbsp;&nbsp; &nbsp;区域右边:整数,&nbsp; &nbsp; 区域下边:整数,&nbsp;&nbsp;&nbsp; 颜色:字符串,&nbsp;&nbsp;&nbsp; 输出找到的x坐标:整型变量,&nbsp;&nbsp;&nbsp; 输出找到的y坐标:整型变量)<br/></font>&nbsp;<br/></p>

马大哈 发表于 2007-5-29 16:02:17

<p>Public Function FindColor(ByVal mX As Long, ByVal mY As Long, ByVal Width As Long, ByVal Height As Long, ByVal Find_Color As Long, ByRef PoX As Long, ByRef PoY As Long)<br/>Dim Bi As BITMAPINFO<br/>Dim LngCol As Long, hMap As Long, LenBuf As Long, R As Long<br/>Dim BmpBuf() As Byte<br/>Dim PX As Long, PY As Long</p><p>&nbsp;&nbsp;&nbsp; On Error GoTo ErrLine</p><p>&nbsp;&nbsp;&nbsp; Find_Color = (&amp;HFF And Find_Color) * &amp;H10000 + (&amp;HFF00&amp; And Find_Color) + _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (&amp;HFF0000 And Find_Color) / &amp;H10000</p><p>&nbsp;&nbsp;&nbsp; With Bi.bmiHeader<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biSize = Len(Bi.bmiHeader)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biWidth = Screen.Width / 15<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biHeight = Screen.Height / 15<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biPlanes = 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biBitCount = 24<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .biCompression = BI_RGB<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LenBuf = (.biWidth) * (.biHeight) * 3<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim BmpBuf(LenBuf - 1)&nbsp;&nbsp;&nbsp; 'MsgBox bmpBuf(2359295)<br/>&nbsp;&nbsp;&nbsp; End With</p><p>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; hMap = GetCurrentObject(GetDC(0), OBJ_BITMAP)<br/>&nbsp;&nbsp;&nbsp; GetDIBits GetDC(0), hMap, 0, Bi.bmiHeader.biHeight, VarPtr(BmpBuf(0)), Bi, DIB_RGB_COLORS</p><p>&nbsp;&nbsp;&nbsp; '从左到右.从下往上 顺序<br/>&nbsp;&nbsp;&nbsp; For PY = Height To mY Step -1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For PX = mX To Width<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CopyMemory LngCol, BmpBuf(R), 3</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LngCol = Find_Color Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PoX = PX - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PoY = PY - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Erase BmpBuf<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R = R + 3<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; Next</p><p>ErrLine:<br/>&nbsp;&nbsp;&nbsp; PoX = -1<br/>&nbsp;&nbsp;&nbsp; PoY = -1<br/>&nbsp;&nbsp;&nbsp; Erase BmpBuf<br/>&nbsp;&nbsp;&nbsp; 'MsgBox "错误号:" &amp; Err.Number &amp; "错误信息:" &amp; Err.Description<br/>End Function</p><p>至于第四个参数ByVal Find_Color As Long,为什么要用字符串?</p>

dabian001 发表于 2007-5-29 17:54:02

<p>大马</p><p></p><p>读出的坐标不对.....可能跟数组有关系////需要改成&nbsp; 2 维的吗???</p><p></p><p></p><p>怎么改成&nbsp; 2维数组...??&nbsp; 我不会改</p>
[此贴子已经被作者于2007-5-29 17:54:45编辑过]

马大哈 发表于 2007-6-1 10:40:27

<p>怎么不对?</p><p>后面两个参数不是宽与高,而是右下角的坐标的.</p><p>Public Function FindColor([左上X],[左上Y],[右下X],[右下Y], , [返回X], [返回Y])<br/></p>
页: [1]
查看完整版本: 帮我改一下