getpixel function returns the color of pixel present at location(x, y).

Declaration :- int getpixel(int x, int y);

C program for getpixel

[pastacode lang=”c” manual=”%23include%3Cgraphics.h%3E%0A%23include%3Cconio.h%3E%0A%20%0Amain()%0A%7B%0A%20%20int%20gd%20%3D%20DETECT%2C%20gm%2C%20color%3B%0A%20%20char%20array%5B50%5D%3B%0A%20%0A%20%20initgraph(%26gd%2C%26gm%2C%22C%3A%5C%5CTC%5C%5CBGI%22)%3B%0A%20%0A%20%20color%20%3D%20getpixel(0%2C%200)%3B%0A%20%0A%20%20sprintf(array%2C%22color%20of%20pixel%20at%20(0%2C0)%20%3D%20%25d%22%2Ccolor)%3B%0A%20%20outtext(array)%3B%0A%20%0A%20%20getch()%3B%0A%20%20closegraph()%3B%0A%20%20return%200%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

As we haven’t drawn anything on screen and by default screen is BLACK, therefore color of pixel at (0,0) is BLACK. So output of program will be color of pixel at (0,0) is 0, as 0 indicates BLACK color.

 

Categorized in: