You are here

getpixel and putpixel functions in C

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

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

C programming code for getpixel and putpixel

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

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