You are here

putpixel function in c

putpixel function plots a pixel at location (x, y) of specified color.

Declaration: void putpixel(int x, int y, int color);

For example,if we want to draw a GREEN color pixel at (35, 45) then we will write putpixel(35, 35, GREEN); in our c program, putpixel function can be used to draw circles, lines and ellipses using various algorithms.

C programming code for putpixel

  1. #include<graphics.h>
  2. #include<conio.h>
  3.  
  4. main()
  5. {
  6.    int gd = DETECT, gm;
  7.  
  8.    initgraph(&gd, &gm, "C:\\TC\\BGI");
  9.  
  10.    putpixel(25, 25, RED);
  11.  
  12.    getch();
  13.    closegraph();
  14.    return 0;
  15. }

Output of this program will be a RED pixel on screen at (25, 25) . Try to spot that pixel with your eyes at left top portion of your computer screen.