vbnet中怎么取得屏幕中的某一点颜色
用API的话希望给出API代码及声明,注意是2005版本的,,在线Wait...
[解决办法]
- VB.NET code
Imports System.Runtime.InteropServicesPublic Class Win32 Declare Auto Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Integer Declare Auto Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As Integer) As Integer Declare Auto Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As IntegerEnd ClassPublic Class MainClass Public Shared Sub Main() Console.WriteLine(Hex(Win32.GetPixel(Win32.GetWindowDC(Win32.GetDesktopWindow()), 100, 100))) End SubEnd Class
[解决办法]
Function GetPointColor(ByVal x As Integer, ByVal y As Integer) As Color
Dim bmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
Graphics.FromImage(bmp).CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size)
Return bmp.GetPixel(x, y)
End Function
call:
msgbox Getpointcolor(1,1).tostring