C语言使用gd库函数详细记录

1.绘图函数

(1)绘制一个像素点的函数

  void gdImageSetPixel(gdImagePtr im, int x, int y, int color)

  参数列表

  第一参数:gdImagePtr类型,为对象

  第二参数:画图的横坐标

  第三参数:画图纵坐标

  第四参数:要绘制的颜色

(2)在两个端点之间画一条直线

   void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)

  参数列表依次是:对象,两个端点的坐标,颜色

(3)用于绘制一个多边形的函数,至少三个

void gdImagePolygon(gdImagePtr im, gdPointPtr points, int pointsTotal, int color)

具体事例

#include<stdio.h>
#include <gdfontl.h>
#include <gd.h>
#include <string.h>

int main(int argc,char **argv)
{
gdImagePtr im;
FILE*pngout;
int black;
int white;
/* Points of polygon */
gdPoint points[3];
im = gdImageCreate(100, 100);
/* Background color (first allocated) */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and
blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a triangle. */
points[0].x = 50;
points[0].y = 0;
points[1].x = 99;
points[1].y = 99;
points[2].x = 0;
points[2].y = 99;
gdImagePolygon(im, points, 3, white);
/* ... Do something with the image, such as
saving it to a file... */
/* Destroy it */
pngout = fopen("test1.png","wb");
gdImagePng(im, pngout);
fclose(pngout);
gdImageDestroy(im);

return 0;

}

 

(4)

  

你可能感兴趣的:(C语言)