Results 1 to 7 of 7

Thread: Display context using C

  1. #1
    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

  2. #2
    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.

  3. #3
    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?

  4. #4
    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!

  5. #5
    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?

  6. #6
    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) ...

  7. #7
    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

Similar Threads

  1. Replies: 5
    Last Post: 13-07-2012, 03:47 PM
  2. Remove VLC From Context Menu
    By Nadiaa in forum Windows Software
    Replies: 6
    Last Post: 12-05-2010, 11:37 PM
  3. What is the Bean Context : Containment Only?
    By NGV BalaKrishna in forum Software Development
    Replies: 4
    Last Post: 17-02-2010, 06:47 AM
  4. Own commands in context menus
    By XDRoX in forum Tips & Tweaks
    Replies: 1
    Last Post: 04-04-2009, 12:33 PM
  5. more options in the context menus ?
    By Kelewyn in forum Operating Systems
    Replies: 2
    Last Post: 17-09-2008, 07:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,585,322.68177 seconds with 16 queries