getpixel() function in C
Last Updated :
23 Jan, 2018
The header file graphics.h contains getpixel() function which returns the color of pixel present at location (x, y).
Syntax :
int getpixel(int x, int y);
Note : By default the screen is BLACK, therefore color of pixel at (0,0) is BLACK.
Below is the implementation of getpixel() function.
#include <graphics.h>
#include <stdio.h>
int main()
{
int gd = DETECT, gm, color;
char arr[50];
initgraph(&gd, &gm, "" );
color = getpixel(0, 0);
sprintf (arr, "color of pixel at (0,0) = %d" ,
color);
outtext(arr);
getch();
closegraph();
return 0;
}
|
Output :
Explanation : As nothing is drawn anything on screen and by default screen is BLACK, therefore color of pixel at (0, 0) is BLACK as 0 indicates BLACK color.
Share your thoughts in the comments
Please Login to comment...