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

  1. #include<graphics.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4.  
  5. main()
  6. {
  7.    int gd = DETECT, gm, x = 100, y = 100, color;
  8.    char arr[100];
  9.  
  10.    initgraph(&gd,&gm,"C:\\TC\\BGI");
  11.  
  12.    putpixel(x, y, RED);
  13.  
  14.    color = getpixel(x, y);
  15.  
  16.    sprintf(arr,"Color of pixel located at point(%d, %d) is %d",x,y,color);
  17.    outtextxy(100,110,arr);
  18.  
  19.    getch();
  20.    closegraph();
  21.    return 0;
  22. }