{"id":363,"date":"2010-07-12T23:35:25","date_gmt":"2010-07-12T21:35:25","guid":{"rendered":"http:\/\/www.albertopasca.it\/whiletrue\/?p=363"},"modified":"2018-05-25T11:26:15","modified_gmt":"2018-05-25T09:26:15","slug":"c-get-pixel-color-at-xy","status":"publish","type":"post","link":"https:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/","title":{"rendered":"[C#] Get Pixel Color At X,Y"},"content":{"rendered":"<p>Hello,<\/p>\n<p>a simple trick for you to\u00a0<strong>get pixel color\u00a0<\/strong>on a particular position of your screen with Windows\u00a0<strong>GDI32.dll<\/strong>\u00a0API libs.<\/p>\n<p>First of all, you need to import\u00a0<em>Win32 API<\/em>:<\/p>\n<p><!--more--><\/p>\n<p>[code lang=&#8221;csharp&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;][DllImport(\u00a0&quot;user32.dll&quot;\u00a0)]<br \/>\nstatic\u00a0extern\u00a0IntPtr GetDC(\u00a0IntPtr hwnd\u00a0);<\/p>\n<p>[DllImport(\u00a0&quot;user32.dll&quot;\u00a0)]<br \/>\nstatic\u00a0extern\u00a0Int32 ReleaseDC(\u00a0IntPtr hwnd, IntPtr hdc\u00a0);<\/p>\n<p>[DllImport(\u00a0&quot;gdi32.dll&quot;\u00a0)]<br \/>\nstatic\u00a0extern\u00a0uint\u00a0GetPixel(\u00a0IntPtr hdc,\u00a0int\u00a0nXPos,\u00a0int\u00a0nYPos\u00a0);[\/code]<\/p>\n<p>after that, create a function like this that return color in\u00a0<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa327164(VS.71).aspx\"><strong>ARGB<\/strong><\/a>:<\/p>\n<p>[code lang=&#8221;csharp&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]static\u00a0public\u00a0System.Drawing.Color\u00a0GetPixelColor(\u00a0int\u00a0x,\u00a0int\u00a0y\u00a0)<br \/>\n{<br \/>\n  IntPtr hdc\u00a0=\u00a0GetDC(\u00a0IntPtr.Zero\u00a0);<br \/>\n  uint\u00a0pixel\u00a0=\u00a0GetPixel(\u00a0hdc, x, y\u00a0);<br \/>\n  ReleaseDC(\u00a0IntPtr.Zero, hdc\u00a0);<br \/>\n  Color color\u00a0=\u00a0Color.FromArgb(\u00a0(\u00a0int\u00a0)(\u00a0pixel\u00a0&amp;amp;\u00a00x000000FF\u00a0),<br \/>\n      (\u00a0int\u00a0)(\u00a0pixel\u00a0&amp;amp;\u00a00x0000FF00\u00a0)\u00a0&amp;gt;&amp;gt;\u00a08,<br \/>\n      (\u00a0int\u00a0)(\u00a0pixel\u00a0&amp;amp;\u00a00x00FF0000\u00a0)\u00a0&amp;gt;&amp;gt;\u00a016\u00a0);<br \/>\n  return\u00a0color;<br \/>\n}[\/code]<\/p>\n<p>you can call it simply\u00a0<strong>GetPixelColor( 0, 100 );<\/strong><\/p>\n<p>That\u2019s all.<\/p>\n<p>Rif:\u00a0<a href=\"http:\/\/www.albertopasca.it\/developer\/cs\/milano\/\">albertopasca.it<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, a simple trick for you to\u00a0get pixel color\u00a0on a particular position of your screen with Windows\u00a0GDI32.dll\u00a0API libs. First of all, you need to import\u00a0Win32 API:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[197,233,370,362,75],"class_list":["post-363","post","type-post","status-publish","format-standard","hentry","category-generic","tag-color","tag-cs","tag-image","tag-pixel","tag-windows"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[C#] Get Pixel Color At X,Y - while (true) {\u00a0}<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[C#] Get Pixel Color At X,Y - while (true) {\u00a0}\" \/>\n<meta property=\"og:description\" content=\"Hello, a simple trick for you to\u00a0get pixel color\u00a0on a particular position of your screen with Windows\u00a0GDI32.dll\u00a0API libs. First of all, you need to import\u00a0Win32 API:\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/\" \/>\n<meta property=\"og:site_name\" content=\"while (true) {\u00a0}\" \/>\n<meta property=\"article:published_time\" content=\"2010-07-12T21:35:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-05-25T09:26:15+00:00\" \/>\n<meta name=\"author\" content=\"Alberto Pasca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lupasca\" \/>\n<meta name=\"twitter:site\" content=\"@lupasca\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alberto Pasca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/\"},\"author\":{\"name\":\"Alberto Pasca\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"headline\":\"[C#] Get Pixel Color At X,Y\",\"datePublished\":\"2010-07-12T21:35:25+00:00\",\"dateModified\":\"2018-05-25T09:26:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/\"},\"wordCount\":203,\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"keywords\":[\"color\",\"cs\",\"image\",\"pixel\",\"windows\"],\"articleSection\":[\"generic\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/\",\"url\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/\",\"name\":\"[C#] Get Pixel Color At X,Y - while (true) {\u00a0}\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\"},\"datePublished\":\"2010-07-12T21:35:25+00:00\",\"dateModified\":\"2018-05-25T09:26:15+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/c-get-pixel-color-at-xy\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[C#] Get Pixel Color At X,Y\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\",\"name\":\"while (true) {\u00a0}\",\"description\":\"notes from a developer, tutorials, how-to, ideas\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\",\"name\":\"Alberto Pasca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"caption\":\"Alberto Pasca\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\"},\"description\":\"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.\",\"sameAs\":[\"https:\\\/\\\/www.albertopasca.it\",\"albertopasca\",\"https:\\\/\\\/x.com\\\/lupasca\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[C#] Get Pixel Color At X,Y - while (true) {\u00a0}","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/","og_locale":"en_US","og_type":"article","og_title":"[C#] Get Pixel Color At X,Y - while (true) {\u00a0}","og_description":"Hello, a simple trick for you to\u00a0get pixel color\u00a0on a particular position of your screen with Windows\u00a0GDI32.dll\u00a0API libs. First of all, you need to import\u00a0Win32 API:","og_url":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/","og_site_name":"while (true) {\u00a0}","article_published_time":"2010-07-12T21:35:25+00:00","article_modified_time":"2018-05-25T09:26:15+00:00","author":"Alberto Pasca","twitter_card":"summary_large_image","twitter_creator":"@lupasca","twitter_site":"@lupasca","twitter_misc":{"Written by":"Alberto Pasca","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/#article","isPartOf":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/"},"author":{"name":"Alberto Pasca","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"headline":"[C#] Get Pixel Color At X,Y","datePublished":"2010-07-12T21:35:25+00:00","dateModified":"2018-05-25T09:26:15+00:00","mainEntityOfPage":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/"},"wordCount":203,"publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"keywords":["color","cs","image","pixel","windows"],"articleSection":["generic"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/","url":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/","name":"[C#] Get Pixel Color At X,Y - while (true) {\u00a0}","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website"},"datePublished":"2010-07-12T21:35:25+00:00","dateModified":"2018-05-25T09:26:15+00:00","breadcrumb":{"@id":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.albertopasca.it\/whiletrue\/c-get-pixel-color-at-xy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.albertopasca.it\/whiletrue\/"},{"@type":"ListItem","position":2,"name":"[C#] Get Pixel Color At X,Y"}]},{"@type":"WebSite","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website","url":"https:\/\/www.albertopasca.it\/whiletrue\/","name":"while (true) {\u00a0}","description":"notes from a developer, tutorials, how-to, ideas","publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.albertopasca.it\/whiletrue\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac","name":"Alberto Pasca","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","caption":"Alberto Pasca"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g"},"description":"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.","sameAs":["https:\/\/www.albertopasca.it","albertopasca","https:\/\/x.com\/lupasca"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/comments?post=363"}],"version-history":[{"count":2,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/363\/revisions"}],"predecessor-version":[{"id":738,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/363\/revisions\/738"}],"wp:attachment":[{"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media?parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/categories?post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/tags?post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}