473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

WILL PAY YOU 10 BUCKS (desperate) to show me how to get color of a specified pixel point

Given the coordinates of a point on the screen (such as 185,185), how do
you get the color of said point using VB.NET 2003.

I have looked EVERYWHERE for this, but to no avail. All the examples I've
seen use old code that is no longer supported in .NET.

I will pay the first person who posts working code 10 bucks from paypal.
I'm desperate, and really want to know how to do this.
..Please don't post VB6 code or anything that contains the statements:
Private Type POINTAPI
X As Long
Y As Long
End Type

since TYPE is not supported in .NET 2003.

I got this code from experts exchange, but it doesn't work- it just keeps
giving me the same dozen digit number over and over again (which has no
meaning to me)
Private Structure POINTAPI
Public X As Long
Public Y As Long
End Structure

Private Declare Function GetCursorPos Lib "user32" (ByVal lpPoint As
POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal
X As Long, ByVal Y As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long,
ByVal hdc As Long) As Long

Private lDesktopDC As Long
Private Sub Form_Load()
lDesktopDC = GetDC(0)
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Form_Unload(ByVal Cancel As Integer)
Call ReleaseDC(0, lDesktopDC)
End Sub
Private Sub Timer1_Timer()
Dim tPt As POINTAPI, lRGB As Long
Call GetCursorPos(tPt)
lRGB = GetPixel(lDesktopDC, tPt.X, tPt.Y)
If lRGB <> -1 Then
Me.BackColor = Color.FromArgb(cint(lRGB))
End If
End Sub

u can email me at @yahoo.com ( the first part reads SIRARTHUR1)
Jul 21 '05 #1
2 1582
Well, this might not be the best way...
But with minor modifications the code you supplied below will work.
Attached is a sample form that is almost identical.
Take into consideration that LONG in VB6 = INTEGER in VB.Net.

There are other more elegant ways, but AFAIK until VB 2005 you still need
Win32API (GDI) to get access to the desktop graphics.

Make a form called "frmPixelColor"
Throw a Timer on it.
Paste this in.
'--------------------------------------------------
Private Structure POINTAPI
Public X As Integer
Public Y As Integer
End Structure

Private Declare Function GetCursorPos _
Lib "user32" (ByVal lpPoint As POINTAPI) As Integer
Private Declare Function GetDC _
Lib "user32" (ByVal hwnd As Integer) As Integer
Private Declare Function GetPixel _
Lib "gdi32" (ByVal hdc As Integer, _
ByVal X As Integer, ByVal Y As Integer) As Integer
Private Declare Function ReleaseDC _
Lib "user32" (ByVal hwnd As Integer, _
ByVal hdc As Integer) As Integer

Private lDesktopDC As Integer

Private Sub Timer1_Tick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick

Dim tPt As Point, lRGB As Integer
tPt = MousePosition
lRGB = GetPixel(lDesktopDC, tPt.X, tPt.Y)
If lRGB <> -1 Then
Me.BackColor = ColorTranslator.FromWin32(lRGB)
End If

End Sub

Private Sub frmPixelColor_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

lDesktopDC = GetDC(0)
Timer1.Interval = 100
Timer1.Enabled = True
End Sub

Private Sub frmPixelColor_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed

Call ReleaseDC(0, lDesktopDC)
End Sub

'--------------------------------------------------

See, the code is virtually identical.

Gerald
"Arthur" <te*****************************@yahoo.com> wrote in message
news:yNjfd.23987$%k.676@pd7tw2no...
Given the coordinates of a point on the screen (such as 185,185), how do
you get the color of said point using VB.NET 2003.

I have looked EVERYWHERE for this, but to no avail. All the examples I've
seen use old code that is no longer supported in .NET.

I will pay the first person who posts working code 10 bucks from paypal.
I'm desperate, and really want to know how to do this.
.Please don't post VB6 code or anything that contains the statements:
Private Type POINTAPI
X As Long
Y As Long
End Type

since TYPE is not supported in .NET 2003.

I got this code from experts exchange, but it doesn't work- it just keeps
giving me the same dozen digit number over and over again (which has no
meaning to me)
Private Structure POINTAPI
Public X As Long
Public Y As Long
End Structure

Private Declare Function GetCursorPos Lib "user32" (ByVal lpPoint As
POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long,
ByVal hdc As Long) As Long

Private lDesktopDC As Long
Private Sub Form_Load()
lDesktopDC = GetDC(0)
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Form_Unload(ByVal Cancel As Integer)
Call ReleaseDC(0, lDesktopDC)
End Sub
Private Sub Timer1_Timer()
Dim tPt As POINTAPI, lRGB As Long
Call GetCursorPos(tPt)
lRGB = GetPixel(lDesktopDC, tPt.X, tPt.Y)
If lRGB <> -1 Then
Me.BackColor = Color.FromArgb(cint(lRGB))
End If
End Sub

u can email me at @yahoo.com ( the first part reads SIRARTHUR1)



Jul 21 '05 #2
> I got this code from experts exchange, but it doesn't work- it just keeps
giving me the same dozen digit number over and over again (which has no
meaning to me)
lRGB = GetPixel(lDesktopDC, tPt.X, tPt.Y)


Well, thats the color that you should be getting. It is giving you
the color, in long format (RGB representation in a long number) of the
point.

So, the code you got from EE is working fine, and probably giving you
your color just fine as well.
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sami | last post by:
Hello, I just started out with Windows.Forms and was going through the MS tutorials. In the tutorial where you can create a non-rectangular shaped window by using your own window painted with...
2
by: Arthur | last post by:
Given the coordinates of a point on the screen (such as 185,185), how do you get the color of said point using VB.NET 2003. I have looked EVERYWHERE for this, but to no avail. All the examples...
0
by: Lucian Wischik | last post by:
I'm using ToolTip.Show(x,y,..) to show my balloon-style tooltip at a specified coordinate. Most of the time it works fine and the "tip" of the balloon points exactly to my specified (x,y)...
7
by: Ladysniper | last post by:
DESPERATE doesn't begin to describe it. Can someone PLEASE tell me what is WRONG with this code? Now..a bit of background. It is a search results page for http://www.azsoma.info/directory.htm....
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
6
by: Victor | last post by:
Hi, I am a newbie in the C# graphical arena and I have the following problem. I have a 2D disk in which I have a few points, each point having x, y coordinates and also a value associated with...
4
by: Martijn Mulder | last post by:
When I zoom in on an image, GDI+ automatically smoothens the edges between the pixels. I am looking for a way to see the individual pixels as squares in the enlarged image, like in MSPaint. I...
0
by: icebeta | last post by:
hi, I'm doing a project in c# that removes the green background in a picture, like a green screen effect in movies. i already made it partially working. but the problem is that it only remove...
8
by: Massimiliano | last post by:
Hi all. How I can retreive a dimension in pixel of a character draw with graphics.drawstring(...). For example: imgFont = New Bitmap(48, 48) ' for now the dimension is fixed g =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.