473,809 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al Cancel As Integer)
Call ReleaseDC(0, lDesktopDC)
End Sub
Private Sub Timer1_Timer()
Dim tPt As POINTAPI, lRGB As Long
Call GetCursorPos(tP t)
lRGB = GetPixel(lDeskt opDC, 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 1607
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 "frmPixelCo lor"
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(ByV al sender As Object, _
ByVal e As System.EventArg s) Handles Timer1.Tick

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

End Sub

Private Sub frmPixelColor_L oad(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load

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

Private Sub frmPixelColor_C losed(ByVal sender As Object, _
ByVal e As System.EventArg s) 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.2398 7$%k.676@pd7tw2 no...
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(ByV al Cancel As Integer)
Call ReleaseDC(0, lDesktopDC)
End Sub
Private Sub Timer1_Timer()
Dim tPt As POINTAPI, lRGB As Long
Call GetCursorPos(tP t)
lRGB = GetPixel(lDeskt opDC, 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(lDeskt opDC, 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
4843
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 some paint utility, I am having some problems with trying to compare the color of the pixel that I retrieve using Bitmap.GetPixel(...) method. My pseudo-code looks like this:...
2
276
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 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.
0
10706
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) coordinates. But if the (x,y) coordinates are too far to the right, then the "tip" of the balloon now points to some spurious coordinate that's unrelated to my (x,y). Why? How can I stop this? How can I make the balloon's tip point exactly where I...
7
1691
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. (use Scottsdale for the city) If you go look, you see that the search results post (I do have my table borders up for debugging) but it doesn't line up with the table above it...the whole scroll background doesn't show up and I cannot get
130
6651
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 in the database show up with *15* decimal places and are ever so slightly off (in the example in the subject line, by about 2E-15). I'm not doing any operations on this column. It's just running a stored procedure which performs a pretty basic...
6
2757
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 it which represents profit (or loss). What I want to do is to create a background with a gradient going from red to green which reflects the values of the existing points. I need to mention that the points do not follow a linear gradient or any...
4
2881
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 searched in vain in the enumerations System.Drawing.Drawing2D.SmoothingMode and System.Drawing.Drawing2D.InterpolationMode to find the constant that does just that. How? Some code to illustrate the problem: using System.Drawing;
0
1573
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 1 shade of green at a time. so if i have a 3 shades of green i need to process it 3 times. but my prof. want it to be done only once. when i load the picture it must remove all the green background. do you have any idea to do this.
8
2112
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 = Graphics.FromImage(imgFont) g.DrawString(ch, fontChoose, Brushes.Black, 0, 0)
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10635
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.