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.

[ad type=”banner”]

C programming code for putpixel

[pastacode lang=”c” manual=”%23include%3Cgraphics.h%3E%0A%23include%3Cconio.h%3E%0A%20%0Amain()%0A%7B%0A%20%20%20int%20gd%20%3D%20DETECT%2C%20gm%3B%0A%20%0A%20%20%20initgraph(%26gd%2C%20%26gm%2C%20%22C%3A%5C%5CTC%5C%5CBGI%22)%3B%0A%20%0A%20%20%20putpixel(25%2C%2025%2C%20RED)%3B%0A%20%0A%20%20%20getch()%3B%0A%20%20%20closegraph()%3B%0A%20%20%20return%200%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

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.
[ad type=”banner”]

Categorized in: