473,396 Members | 1,784 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,396 software developers and data experts.

C# Pixel Colour Help

Okay, well I am trying to detect when a program is done, by detecting the colour change of the pixels.

See, when the program is done, it has gets a big blue button at the bottom to exit it. And i want my C# program to detect when it is done, and exit that program.

I have absolutely no idea on how to do this. I hope you guys have answers =)
Feb 9 '08 #1
3 1870
kenobewan
4,871 Expert 4TB
What have you tried so far? Please provide more info. Thanks.
Feb 10 '08 #2
Well, i have tried using X/Y coordinates, but i don't really know how to use those either. Preferably pixel detection though.

I'll post my source code here for something that i did do, but its not really that close to what i want...

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9.  
  10. namespace WindowsApplication1
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private Bitmap myBitmap;
  19.  
  20.         public class Win32APICall
  21.         {
  22.             [DllImport("gdi32.dll", EntryPoint = "DeleteDC")]
  23.             public static extern IntPtr DeleteDC(IntPtr hdc);
  24.  
  25.             [DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
  26.             public static extern IntPtr DeleteObject(IntPtr hObject);
  27.  
  28.             [DllImport("gdi32.dll", EntryPoint = "BitBlt")]
  29.             public static extern bool BitBlt(IntPtr hdcDest, int nXDest,
  30.                 int nYDest, int nWidth, int nHeight, IntPtr hdcSrc,
  31.                 int nXSrc, int nYSrc, int dwRop);
  32.  
  33.             [DllImport("gdi32.dll", EntryPoint = "CreateCompatibleBitmap")]
  34.             public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,
  35.                 int nWidth, int nHeight);
  36.  
  37.             [DllImport("gdi32.dll", EntryPoint = "CreateCompatibleDC")]
  38.             public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
  39.  
  40.             [DllImport("gdi32.dll", EntryPoint = "SelectObject")]
  41.             public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobjBmp);
  42.  
  43.             [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
  44.             public static extern IntPtr GetDesktopWindow();
  45.  
  46.             [DllImport("user32.dll", EntryPoint = "GetDC")]
  47.             public static extern IntPtr GetDC(IntPtr hWnd);
  48.  
  49.             [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
  50.             public static extern int GetSystemMetrics(int nIndex);
  51.  
  52.             [DllImport("user32.dll", EntryPoint = "ReleaseDC")]
  53.             public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
  54.  
  55.             public static Bitmap GetDesktop()
  56.             {
  57.                 int screenX;
  58.                 int screenY;
  59.                 IntPtr hBmp;
  60.                 IntPtr hdcScreen = GetDC(GetDesktopWindow());
  61.                 IntPtr hdcCompatible = CreateCompatibleDC(hdcScreen);
  62.  
  63.                 screenX = GetSystemMetrics(0);
  64.                 screenY = GetSystemMetrics(1);
  65.                 hBmp = CreateCompatibleBitmap(hdcScreen, screenX, screenY);
  66.  
  67.                 if (hBmp != IntPtr.Zero)
  68.                 {
  69.                     IntPtr hOldBmp = (IntPtr)SelectObject(hdcCompatible, hBmp);
  70.                     BitBlt(hdcCompatible, 0, 0, screenX, screenY, hdcScreen, 0, 0, 13369376);
  71.  
  72.                     SelectObject(hdcCompatible, hOldBmp);
  73.                     DeleteDC(hdcCompatible);
  74.                     ReleaseDC(GetDesktopWindow(), hdcScreen);
  75.  
  76.                     Bitmap bmp = System.Drawing.Image.FromHbitmap(hBmp);
  77.  
  78.                     DeleteObject(hBmp);
  79.                     GC.Collect();
  80.  
  81.                     return bmp;
  82.                 }
  83.  
  84.                 return null;
  85.             }
  86.         }
  87.  
  88.         private void Form1_Load(object sender, EventArgs e)
  89.         {
  90.  
  91.         }
  92.  
  93.         private void label1_MouseDown(object sender, MouseEventArgs e)
  94.         {
  95.             myBitmap = Win32APICall.GetDesktop();
  96.         }
  97.  
  98.         private void label1_MouseUp(object sender, MouseEventArgs e)
  99.         {
  100.             Color myColor = myBitmap.GetPixel(MousePosition.X, MousePosition.Y);
  101.             label1.BackColor = myColor;
  102.         }
  103.     }
  104. }
And with that, you would just click the label, and hold you mouse, and drag it onto a different color, and the label would grab that color. But...how do i "detect" a color?
Feb 10 '08 #3
Why is nobody posting....='(
Feb 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Derek Scollon | last post by:
I'm using PHP4.2.2 with gd on a Linux platform and am having difficulty in solving a little problem despite going through the definitions of the various image functions. If you load a...
7
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...
3
by: Mark Ingram | last post by:
Hi, ive got an imagine in a PictureBox, and would like to get the colour of the pixel when the mouse is over the control. From what ive (briefly) seen, there is no way to do this directly in C# and...
4
by: ChillUmesh | last post by:
can we do a program to change colour of each pixel of the form. If so can anyone help me in this. thnx.....
4
by: Johny | last post by:
I use PIL to write some text to a picture.The text must be seen wery clearly. I write the text to different pictures but to the same position. As pictures maybe different, colour, in the...
2
by: kuratkull | last post by:
Hello, I haven't asked If I wasn't really confused :) OK, so I am just beginning SDL programming in C, and I was running fine, until I tried getting a pixel colour. Basically, I am trying to...
8
by: =?Utf-8?B?S2Vsdmlu?= | last post by:
Hi all, I am writing an application to detect the dead pixel of LCD panel by using visual C++ (MFC). My flow is follow: 1. Display a dialog with a start button. When the user press the start...
4
by: cjstuttle | last post by:
Could anyone help me, I'm a python noob and need some help. im trying to find some code that will, given a screen co-ordinate, will give me the colour of that pixel in RGB. i have found a lot about...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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...
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.