sdlangers Posted June 30, 2003 Posted June 30, 2003 Hi guys, this is a repost - thanks volte force and divil for your help so far... this code is not returning the correct colors from the desktop.. can anyone see what im doing wrong? thanks heres the code... ' GDI Functions Public Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer) As Integer ' User32 Functions Public Declare Function GetDesktopWindow Lib "user32.dll" Alias "GetDesktopWindow" () As IntPtr Public Declare Function GetWindowDC Lib "user32.dll" Alias "GetWindowDC" (ByVal ptr As Int32) As IntPtr Public Declare Function ReleaseDC Lib "user32.dll" Alias "ReleaseDC" (ByVal hWnd As IntPtr, ByVal hDc As IntPtr) As IntPtr Public Function checkPixel(ByVal X As Integer, ByVal Y As Integer) As Integer Dim hDC As IntPtr ' Get Desktop hDC hDC = GetWindowDC(GetDesktopWindow().ToInt32) ' Get Pixel checkPixel = GetPixel(hDC, X, Y) ' Release Desktop hDC ReleaseDC(GetDesktopWindow(), hDC) End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim c As New Color() Dim i As Integer ' get color integer value i = checkPixel(100, 50) ' convert to color and display c = Color.FromArgb(i) MsgBox("Color = " & CStr(i) & " - " & c.R & ", " & c.G & ", " & c.B) End Sub Quote
Moderators Robby Posted July 1, 2003 Moderators Posted July 1, 2003 try putting the ReleaseDC() near the end of the button_click Quote Visit...Bassic Software
sdlangers Posted July 1, 2003 Author Posted July 1, 2003 robby - thanks.. but that doesnt work.. the getPixel returns an integer value, but it doesnt convert to the correct color maybe the way im trying to convert it is wrong? thanks Quote
Moderators Robby Posted July 1, 2003 Moderators Posted July 1, 2003 Can you provide the value of i (a few samplings). I've used GetPixel but I can't remember the value range. Quote Visit...Bassic Software
sdlangers Posted July 1, 2003 Author Posted July 1, 2003 thanks robby... okay one value that comes up is 14610415 but it seems to come up no matter what the pixel color is at the X,Y coordinates.. you could cut and paste my above code into a form if you need the example.. thats all the code i have.. thanks danny. Quote
*Experts* Volte Posted July 1, 2003 *Experts* Posted July 1, 2003 Try this instead:c = ColorTranslator.FromWin32(i) Quote
Moderators Robby Posted July 1, 2003 Moderators Posted July 1, 2003 Volte's solution works perfectly, if you want to see the results change then change the colors at that x,y location. Quote Visit...Bassic Software
sdlangers Posted July 1, 2003 Author Posted July 1, 2003 great.. ill try that.. it was obviously the way i was trying to convert the int to a color thanks guys. Quote
Recommended Posts