You are here

getpixel function in c

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

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

C program for getpixel

#include<graphics.h>
#include<conio.h>

int main()
{
  int gd = DETECT, gm, color;
  char array[50];

  initgraph(&gd,&gm,"C:\\TC\\BGI");

  color = getpixel(0, 0);

  sprintf(array,"color of pixel at (0,0) = %d", color);
  outtext(array);

  getch();
  closegraph();
  return 0;
}

Since we haven't drawn anything on the screen, and the default screen color is BLACK, the color of the pixel at (0,0) is BLACK. Thus, the program's output will be 0, as it indicates BLACK color.