How to Draw a Pixel in Graphics
What is Pixel in Computer Graphics
Pixel is a term used to describe the smallest unit of a digital image or graphic. It is the smallest individual component in an image. Each pixel is typically represented by a single number or color, which together form an image.
How to Draw Pixel in Graphics?
The simplest way to draw a pixel in C Graphics is to use the putpixel() function. This function takes three parameters, the x coordinate, the y coordinate of the pixel, and color of single pixel on the screen at the specified coordinates.
This program is the first program of Computer Graphics in C. It is also a good example of putpixel function of graphics library. In this program, we are going to draw a pixel in graphics of Red color on the X,Y location of the screen
Syntax:
void putpixel(x,y,color);
here:
x and y are the coordinates of the pixel and color is the color that you want the pixel to be.
Example:
putpixel(100, 100, RED);
This statement will draw a red pixel at the coordinates (100,100).
Program code to Draw a Pixel in Graphics
1 2 3 4 5 6 7 8 9 10 11 12 | //C Program to Draw Pixel in Graphics. #include<graphics.h> #include<stdio.h> #include<conio.h> void main( ) { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\TURBOC3\BGI"); putpixel(100,100,RED); getch( ); closegraph(); } |
Output :