Hello,
I must find a color code in an image. Either it is an image file, or is directly addressed from the screen. It must be very fast, then the solution proposed in memory lowest'm particularly. I'm looking for this afternoon tutorials on google but I hope I can find nothing. If someone has a complete, I am taker.
Code:
# include <stdio.h>
# include <stdlib.h>
# include <windows.h>
int main (void)
{
/ / Move the window
HWND handle = FindWindow ( "MSPaintApp", NULL);
SetForegroundWindow (handle);
HDC hDC = GetDC (0);
FILE * save = fopen ( "save.txt", "w");
/ / Retrieve the screen resolution
int ResX = GetSystemMetrics (SM_CXSCREEN);
int ResY = GetSystemMetrics (SM_CYSCREEN);
/ / Image Processing
int i = ResX;
int j = ResY;
int counter = 0;
int nbr_loop = i * j;
int progress;
printf ( "loops:% d", nbr_loop);
getchar ();
for (i = 1; i <= ResX i + +)
{
for (j = 1; j <= ResY j + +)
{
increase = ((counter * 100) / nbr_loop);
COLORREF code_color;
code_couleur = GetPixel (hDC, i, j);
fprintf (save, "color code:% ld | loop:% d | progression:% d \ n", code_color, counter, progression);
printf ( "color code:% ld | loop:% d | progression:% d \ n", code_color, counter, progression);
counter + +;
}
}
getchar ();
}
}
It works with GetDC (0) is to handle the office but when I choose another handle the function that returns me -1 and I do not understand why? While walking, processing time is too long. Are you a quicker way please?
Thank you in advance
Bookmarks