Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 15-12-2008
Member
 
Join Date: Dec 2008
Posts: 102
Display context using C

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
Reply With Quote
  #2  
Old 15-12-2008
Member
 
Join Date: Nov 2008
Posts: 211
Re: Display context using C

Hello,

At speed, it is possible to go faster by avoiding write to a file after each pixel read.

So, I do not understand why GetDC (handle) does not work as expected ... Perhaps he should try GetWindowDC.

I look in more detail when I have a windows on hand.
Reply With Quote
  #3  
Old 15-12-2008
Member
 
Join Date: Dec 2008
Posts: 102
Re: Display context using C

Yes indeed, by not displaying the calculations in the console, but it is still far too slow. Should be treated the image in the second. Are even faster?
Reply With Quote
  #4  
Old 15-12-2008
Member
 
Join Date: Dec 2008
Posts: 39
Re: Display context using C

Already, you do a GetDC (), but I see no ReleaseDC () in your code. Not good!
Reply With Quote
  #5  
Old 15-12-2008
Member
 
Join Date: Dec 2008
Posts: 102
Re: Display context using C

Indeed, I copied the wrong code but there is! No function faster to process the image please?
Reply With Quote
  #6  
Old 15-12-2008
Member
 
Join Date: Dec 2008
Posts: 42
Re: Display context using C

BitBlt () to copy a CD directly in another.
Then you can use functions slower, or directly to work in a DIB (Device-Independent Bitmap) ...
Reply With Quote
  #7  
Old 15-12-2008
Member
 
Join Date: Dec 2008
Posts: 102
Re: Display context using C

Thank you but really I looked I can not find a tutorial that explains how it works.

Anyways Thank you
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Display context using C"
Thread Thread Starter Forum Replies Last Post
Opera doesn't display context menu when right clicking from the bookmarks bar in Opera 12 RC3 natured Technology & Internet 5 13-07-2012 03:47 PM
Remove VLC From Context Menu Nadiaa Windows Software 6 12-05-2010 11:37 PM
What is the Bean Context : Containment Only? NGV BalaKrishna Software Development 4 17-02-2010 06:47 AM
Own commands in context menus XDRoX Tips & Tweaks 1 04-04-2009 12:33 PM
more options in the context menus ? Kelewyn Operating Systems 2 17-09-2008 07:49 PM


All times are GMT +5.5. The time now is 03:53 PM.