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

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

C program for getpixel

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

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;
}

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: