You are here

getpixel and putpixel functions in c

Declarations :-

int getpixel(int x, int y);
void putpixel(int x, int y, int color);

getpixel returns the color of pixel present at point(x, y).
putpixel plots a pixel at a point(x, y) of specified color.

C programming code for getpixel and putpixel

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
 
main()
{
   int gd = DETECT, gm, x = 100, y = 100, color;
   char arr[100];
 
   initgraph(&gd,&gm,"C:\\TC\\BGI");
 
   putpixel(x, y, RED);
 
   color = getpixel(x, y);
 
   sprintf(arr,"Color of pixel located at point(%d, %d) is %d",x,y,color);
   outtextxy(100,110,arr);
 
   getch();
   closegraph();
   return 0;
}