473,657 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the color of a pixel in C#

I have an object derived from Control and I place an icon in it during Paint
handler. I now want to get the color of a particular pixel in my control. In
C++ I could use CDC::GetPixel(x ,y). Is there some way to do this in C#, and
if not, how do I do it in unmanaged code?
Thanks in advance.
Nov 15 '05 #1
1 10033
The GDI+ FAQ has an article on how to capture a control or the screen.
Essentially GDI+ DC's don't have a bitmap that you can peek so you have to
grab the bitmap from the window or screen and do getpixel on the captured
image.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Check out February's edition of Well Formed.
Non-client drawing, Graphics Transform stack and Flood-Filling
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Valerie Hough" <su*****@hcs-usa.com> wrote in message
news:eH******** ******@TK2MSFTN GP10.phx.gbl...
I have an object derived from Control and I place an icon in it during Paint handler. I now want to get the color of a particular pixel in my control. In C++ I could use CDC::GetPixel(x ,y). Is there some way to do this in C#, and if not, how do I do it in unmanaged code?
Thanks in advance.

Nov 15 '05 #2

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

Similar topics

7
3393
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
3848
by: sympatico | last post by:
im trying to read an image(*.bmp) from file and then color the black pixels in it to the color i want using argb. Below is the code of what im trying to do but this gives me an error "setPixel is not supported for images with indexed pixel format" Please tell me what im doing wrong. Dim c1 As Color = Color.Black Dim c2 As Color = Color.FromArgb(CInt(colour)) Dim bm AsNew Bitmap(img) Dim eX AsInteger
2
4599
by: dever | last post by:
I checked my color printers's Printersettings.SupportsColor, which all showed false. What is wrong that I could not use this property. Also, what other way to detect if a printer is color printer. TIA
7
1741
by: walter.alex | last post by:
November 16 2005 -- The recent launch of the new 5 year advertising solution from MillionPixelClick.com means the pixel advertising craze will continue unabated. Selling advertising space by the pixel the new form of advertising is proving popular with both clients and providers alike. Designed to boost traffic, an image is placed on MillionPixelClick.com with a link to your website. These pixels will be visible for at least 5 years....
2
2023
by: fripper | last post by:
I am using VB 2005 and want to generate a graphic in a picture box control where the color of each pixel is determined by particular values calculated for each pixel. These values are manipulated in such a way that I come up with three values (each in the range 0-155) and I want to use these for the RGB values of the color of the associated pixel. My question is: In VB 2005 how do I set a particular pixel to a color with a given set of...
33
2415
by: Dave (DreamIsle) | last post by:
Hello. I'm working on a layout that I need to be pixel specific. How can I get the font to stay precisely the height I need? Specifying line-height or font-size in px doesn't yield the results I need. The font size scales when I change the browser's font size and the text moves from where I need it.
30
9056
by: Chaos | last post by:
As my first attempt to loop through every pixel of an image, I used for thisY in range(0, thisHeight): for thisX in range(0, thisWidth): #Actions here for Pixel thisX, thisY But it takes 450-1000 milliseconds I want speeds less than 10 milliseconds
6
4712
by: Hooyoo | last post by:
I want to get the color of the specified pixel in the screen. Firstly I get the position of the cursor: //Get the position of cursor. Point position = Cursor.Position; Next I want to get the color using the position of the cursor. Anybody here can show me some demo codes? Thanks.
8
1908
by: JEO | last post by:
I have a Visual basic 3 App that I am converting to VBA in Microsoft Access 2003. The VB3 app successfully recolors a bitmap image with code using pixel locations when clicking on option buttons used for color selection. An example is: Grphecho!Picture3.PSet (xpos, ypos), RGB(RRGB, GRGB, BRGB) where the pixel positions are xpos and ypos in a Picture box(Picture3) using the Pset method. I know about the need for twips instead of pixels...
0
1559
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.
0
8399
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
8827
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...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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
8606
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
7337
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
6169
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
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.