index.html
来自「CA仿真模型中SLEUTH模型」· HTML 代码 · 共 1,606 行 · 第 1/5 页
HTML
1,606 行
not need to concern yourself with the rest of the components of this structure.<PRE>typedef struct { /* # of characters in font */ int nchars; /* First character is numbered... (usually 32 = space) */ int offset; /* Character width and height */ int w; int h; /* Font data; array of characters, one row after another. Easily included in code, also easily loaded from data files. */ char *data;} gdFont;</PRE><DT><A NAME="gdFontPtr">gdFontPtr</A> <strong>(TYPE)</strong><DD>A pointer to a font structure. Text-output functions expect theseas their second argument, following the <A HREF="#gdImagePtr">gdImagePtr</A> argument. Two such pointers are declared in theprovided include files gdfonts.h and gdfontl.h.<DT><A NAME="gdPoint">gdPoint</A> <strong>(TYPE)</strong><DD>Represents a point in the coordinate space of the image; usedby <A HREF="#gdImagePolygon">gdImagePolygon</A> and<A HREF="#gdImageFilledPolygon">gdImageFilledPolygon</A>.<PRE>typedef struct { int x, y;} gdPoint, *gdPointPtr;</PRE><DT><A NAME="gdPointPtr">gdPointPtr</A> <strong>(TYPE)</strong><DD>A pointer to a <A HREF="#gdPoint">gdPoint</A> structure; passedas an argument to <A HREF="#gdImagePolygon">gdImagePolygon</A>and <A HREF="#gdImageFilledPolygon">gdImageFilledPolygon</A>.</DL><H3><A NAME="creating">Image creation, destruction, loading and saving</A></H3><DL><DT><A NAME="gdImageCreate">gdImageCreate(sx, sy)</A> <strong>(FUNCTION)</strong><DD>gdImageCreate is called to create images. Invoke gdImageCreatewith the x and y dimensions of the desired image. gdImageCreatereturns a <A HREF="#gdImagePtr">gdImagePtr</A> to the new image, or NULL if unable toallocate the image. The image must eventually be destroyedusing <A HREF="#gdImageDestroy">gdImageDestroy()</A>.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;im = gdImageCreate(64, 64);/* ... Use the image ... */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageCreateFromGif">gdImageCreateFromGif(FILE *in)</A> <strong>(FUNCTION)</strong><DD>gdImageCreateFromGif is called to load images from GIF format files. Invoke gdImageCreateFromGif with an already opened pointer to a file containing the desired image. gdImageCreateFromGifreturns a <A HREF="#gdImagePtr">gdImagePtr</A> to the new image, or NULL if unable to load the image (most often because the file is corrupt or does not contain a GIF image). gdImageCreateFromGif does <em>not</em>close the file. You can inspect the sx and sy members of theimage to determine its size. The image must eventually be destroyedusing <A HREF="#gdImageDestroy">gdImageDestroy()</A>.<PRE><A HREF="#gdImagePtr">gdImagePtr</A> im;... inside a function ...FILE *in;in = fopen("mygif.gif", "rb");im = gdImageCreateFromGif(in);fclose(in);/* ... Use the image ... */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageCreateFromGd">gdImageCreateFromGd(FILE *in)</A> <strong>(FUNCTION)</strong><DD>gdImageCreateFromGd is called to load images from gd format files. Invoke gdImageCreateFromGdwith an already opened pointer to a file containing the desired imagein the <A HREF="#gdformat">gd file format</A>, which is specific to gd and intended for very fast loading. (It is <em>not</em> intended for compression; for compression, use GIF.)gdImageCreateFromGdreturns a <A HREF="#gdImagePtr">gdImagePtr</A> to the new image, or NULL if unable to load the image (most often because the file is corrupt or does not contain a gd format image). gdImageCreateFromGd does <em>not</em>close the file. You can inspect the sx and sy members of theimage to determine its size. The image must eventually be destroyedusing <A HREF="#gdImageDestroy">gdImageDestroy()</A>.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;FILE *in;in = fopen("mygd.gd", "rb");im = gdImageCreateFromGd(in);fclose(in);/* ... Use the image ... */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageCreateFromXbm">gdImageCreateFromXbm(FILE *in)</A> <strong>(FUNCTION)</strong><DD>gdImageCreateFromXbm is called to load images from X bitmap formatfiles. Invoke gdImageCreateFromXbmwith an already opened pointer to a file containing the desired image. gdImageCreateFromXbmreturns a <A HREF="#gdImagePtr">gdImagePtr</A> to the new image, or NULL if unable to load the image (most often because the file is corrupt or does not contain an X bitmap format image). gdImageCreateFromXbm does <em>not</em> close the file. You can inspect the sx and sy members of theimage to determine its size. The image must eventually be destroyedusing <A HREF="#gdImageDestroy">gdImageDestroy()</A>.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;FILE *in;in = fopen("myxbm.xbm", "rb");im = gdImageCreateFromXbm(in);fclose(in);/* ... Use the image ... */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageDestroy">gdImageDestroy(gdImagePtr im)</A> <STRONG>(FUNCTION)</STRONG><DD>gdImageDestroy is used to free the memory associated withan image. It is important to invoke gdImageDestroy before exiting your program or assigning a new image toa <A HREF="#gdImagePtr">gdImagePtr</A> variable.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;im = <A HREF="#gdImageCreate">gdImageCreate</A>(10, 10);/* ... Use the image ... *//* Now destroy it */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageGif">void gdImageGif(gdImagePtr im, FILE *out)</A><STRONG>(FUNCTION)</STRONG> <DD>gdImageGif outputs the specified image to the specifiedfile in GIF format. The file must be open for writing. Under MSDOS,it is important to use "wb" as opposed to simply "w"as the mode when opening the file, and under Unix thereis no penalty for doing so. gdImageGif does <em>not</em>close the file; your code must do so.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;int black, white;FILE *out;/* Create the image */im = <A HREF="#gdImageCreate">gdImageCreate</A>(100, 100);/* Allocate background */white = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 255, 255, 255);/* Allocate drawing color */black = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 0, 0, 0);/* Draw rectangle */<A HREF="#gdImageRectangle">gdImageRectangle</A>(im, 0, 0, 99, 99, black);/* Open output file in binary mode */out = fopen("rect.gif", "wb");/* Write GIF */gdImageGif(im, out);/* Close file */fclose(out);/* Destroy image */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageGd">void gdImageGd(gdImagePtr im, FILE *out)</A><STRONG>(FUNCTION)</STRONG> <DD>gdImageGd outputs the specified image to the specifiedfile in the <A HREF="#gdformat">gd image format</A>. The file must be open for writing. Under MSDOS, it is important to use "wb" as opposed to simply "w" as the mode when opening the file, and under Unix there is no penalty for doing so. gdImageGif does <em>not</em>close the file; your code must do so.<P>The gd image format is intended for fast reads and writes ofimages your program will need frequently to build otherimages. It is <em>not</em> a compressed format, and is not intendedfor general use.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;int black, white;FILE *out;/* Create the image */im = <A HREF="#gdImageCreate">gdImageCreate</A>(100, 100);/* Allocate background */white = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 255, 255, 255);/* Allocate drawing color */black = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 0, 0, 0);/* Draw rectangle */<A HREF="#gdImageRectangle">gdImageRectangle</A>(im, 0, 0, 99, 99, black);/* Open output file in binary mode */out = fopen("rect.gd", "wb");/* Write gd format file */gdImageGd(im, out);/* Close file */fclose(out);/* Destroy image */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE></DL><H3><A NAME="drawing">Drawing Functions</A></H3><DL><DT><A NAME="gdImageSetPixel">void gdImageSetPixel(gdImagePtr im, int x, int y, int color)</A> <STRONG>(FUNCTION)</STRONG> <DD>gdImageSetPixel sets a pixel to a particular color index. Always usethis function or one of the other drawing functions to access pixels;do not access the pixels of the <A HREF="#gdImage">gdImage</A> structure directly.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;int black;int white;im = <A HREF="#gdImageCreate">gdImageCreate</A>(100, 100);/* Background color (first allocated) */black = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */white = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 255, 255, 255); /* Set a pixel near the center. */gdImageSetPixel(im, 50, 50, white);/* ... Do something with the image, such as saving it to a file... *//* Destroy it */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageLine">void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)</A><STRONG>(FUNCTION)</STRONG> <DD>gdImageLine is used to draw a line between two endpoints (x1,y1 and x2, y2).The line is drawn using the color index specified. Note that the colorindex can be an actual color returned by <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A> or one of <A HREF="#gdStyled">gdStyled</A>,<A HREF="#gdBrushed">gdBrushed</A> or <A HREF="#gdStyledBrushed">gdStyledBrushed</A>.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;int black;int white;im = <A HREF="#gdImageCreate">gdImageCreate</A>(100, 100);/* Background color (first allocated) */black = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */white = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 255, 255, 255); /* Draw a line from the upper left corner to the lower right corner. */gdImageLine(im, 0, 0, 99, 99, white);/* ... Do something with the image, such as saving it to a file... *//* Destroy it */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageDashedLine">void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)</A><STRONG>(FUNCTION)</STRONG> <DD>gdImageDashedLine is provided <strong>solely for backwards compatibility</strong> with gd 1.0. New programs should draw dashed lines usingthe normal <A HREF="#gdImageLine">gdImageLine</A> function and thenew <A HREF="#gdImageSetStyle">gdImageSetStyle</A> function.<P>gdImageDashedLine is used to draw a dashed line between two endpoints (x1,y1 and x2, y2).The line is drawn using the color index specified. The portions of the linethat are not drawn are left transparent so the background is visible.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;int black;int white;im = <A HREF="#gdImageCreate">gdImageCreate</A>(100, 100);/* Background color (first allocated) */black = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */white = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 255, 255, 255); /* Draw a dashed line from the upper left corner to the lower right corner. */gdImageDashedLine(im, 0, 0, 99, 99);/* ... Do something with the image, such as saving it to a file... *//* Destroy it */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImagePolygon">void gdImagePolygon(gdImagePtr im, gdPointPtr points, int pointsTotal, int color)</A><STRONG>(FUNCTION)</STRONG> <DD>gdImagePolygon is used to draw a polygon with the verticies(at least 3) specified, using the color index specified. See also <A HREF="#gdImageFilledPolygon">gdImageFilledPolygon</A>.<PRE>... inside a function ...<A HREF="#gdImagePtr">gdImagePtr</A> im;int black;int white;/* Points of polygon */<A HREF="#gdPoint">gdPoint</A> points[3];im = <A HREF="#gdImageCreate">gdImageCreate</A>(100, 100);/* Background color (first allocated) */black = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */white = <A HREF="#gdImageColorAllocate">gdImageColorAllocate</A>(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 */<A HREF="#gdImageDestroy">gdImageDestroy</A>(im);</PRE><DT><A NAME="gdImageRectangle">void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color)</A><STRONG>(FUNCTION)</STRONG> <DD>gdImageRectangle is used to draw a rectangle with the two corners
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?