當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C語言 putpixel()用法及代碼示例


頭文件graphics.h包含putpixel()函數,該函數在指定顏色的位置(x,y)處繪製像素。句法:

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

where, 
(x, y) is the location at which pixel
is to be put , and color specifies 
the color of the pixel.

說明:可以使用putpixel(50,40,RED)繪製(50,40)處的RED彩色像素。 putpixel()函數可用於使用各種算法繪製圓,線和橢圓。

下麵是putpixel()函數的實現。


// C Implementation for putpixel() 
#include <graphics.h> 
#include <stdio.h> 
  
// driver code 
int main() 
{ 
    // gm is Graphics mode which is 
    // a computer display mode that 
    // generates image using pixels. 
    // DETECT is a macro defined in 
    // "graphics.h" header file 
    int gd = DETECT, gm, color; 
  
    // initgraph initializes the 
    // graphics system by loading a 
    // graphics driver from disk 
    initgraph(&gd, &gm, ""); 
  
    // putpixel function 
    putpixel(85, 35, GREEN); 
    putpixel(30, 40, RED); 
    putpixel(115, 50, YELLOW); 
    putpixel(135, 50, CYAN); 
    putpixel(45, 60, BLUE); 
    putpixel(20, 100, WHITE); 
    putpixel(200, 100, LIGHTBLUE); 
    putpixel(150, 100, LIGHTGREEN); 
    putpixel(200, 50, YELLOW); 
    putpixel(120, 70, RED); 
  
    getch(); 
  
    // closegraph function closes the 
    // graphics mode and deallocates 
    // all memory allocated by 
    // graphics system . 
    closegraph(); 
  
    return 0; 
}

輸出:




相關用法


注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 putpixel() function in C。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。