|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to get the color of the specified pixel in the screen?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. Hello Hooyoo,
Use GetPixel method of WinAPI. Sample is there http://pinvoke.net/default.aspx/gdi32/GetPixel.html H> I want to get the color of the specified pixel in the screen. H> Firstly I get the position of the cursor: H> //Get the position of cursor. H> Point position = Cursor.Position; H> Next I want to get the color using the position of the cursor. H> Anybody here can show me some demo codes? H> H> Thanks. H> --- WBR, Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour "At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche Michael Nemtsev <nemt***@msn.com> wrote:
Looking at that page, I think it has a leak. It should ReleaseDC(hwnd,hdc) the hdc that it acquired. Ah, it's a wiki. I guess I'll go and change it. -- Lucian Thank you, Michael.
But actually I don't like use API in C#, I think it makes ungraceful codes. So hopefully there are some methonds of .Net Class Libraries can implement that. Michael Nemtsev wrote: Show quoteHide quote > Hello Hooyoo, > > Use GetPixel method of WinAPI. > Sample is there http://pinvoke.net/default.aspx/gdi32/GetPixel.html > > H> I want to get the color of the specified pixel in the screen. > H> Firstly I get the position of the cursor: > H> //Get the position of cursor. > H> Point position = Cursor.Position; > H> Next I want to get the color using the position of the cursor. > H> Anybody here can show me some demo codes? > H> > H> Thanks. > H> > --- > WBR, > Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour > > "At times one remains faithful to a cause only because its opponents do not > cease to be insipid." (c) Friedrich Nietzsche Hi,
"Hooyoo" <zhao_huy***@126.com> wrote in message Unfortunately you will have to use it, there is nothing in the framework for news:1166174019.740417.85170@n67g2000cwd.googlegroups.com... > Thank you, Michael. > But actually I don't like use API in C#, I think it makes ungraceful > codes. > So hopefully there are some methonds of .Net Class Libraries can > implement that. doing what you want. it's after all platform dependand. There is nothing wrong in using the win API you know -- Ignacio Machin machin AT laceupsolutions com Thanks, got it.
"Ignacio Machin ( .NET/ C# MVP ) дµÀ£º " Show quoteHide quote > Hi, > > "Hooyoo" <zhao_huy***@126.com> wrote in message > news:1166174019.740417.85170@n67g2000cwd.googlegroups.com... > > Thank you, Michael. > > But actually I don't like use API in C#, I think it makes ungraceful > > codes. > > So hopefully there are some methonds of .Net Class Libraries can > > implement that. > > Unfortunately you will have to use it, there is nothing in the framework for > doing what you want. it's after all platform dependand. > > There is nothing wrong in using the win API you know > > > -- > Ignacio Machin > machin AT laceupsolutions com "Hooyoo" <zhao_huy***@126.com> wrote in message In addition to what Michael wrote (I'm assuming there's no practical way to news:1166154771.588175.143310@16g2000cwy.googlegroups.com... >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? get a Graphics object representing the screen DC in .NET)... Keep in mind that reading from the video card frame buffer is slow, at least with AGP cards. So hopefully you don't need to get the pixel's color very frequently. Also keep in mind that when an application is using an overlay buffer (pretty common with video media players, not very common with anything else), getting the color of a pixel within the overlay will not get the actual color being displayed there. It will usually be black, but if not it will be some other default color rather than the pixel you're actually seeing. Pete
Other interesting topics
|
|||||||||||||||||||||||