#include <stdio.h>#include "gd.h"#include "gdfontg.h"#include "gdfonts.h"Go to the source code of this file.
Functions | |
| int | main (void) |
| int main | ( | void | ) |
Definition at line 6 of file gddemo.cpp.
References gdFontGiant, gdFontSmall, gdImageArc(), gdImageColorAllocate(), gdImageColorTransparent(), gdImageCopyResized(), gdImageCreate(), gdImageCreateFromGif(), gdImageDestroy(), gdImageFill(), gdImageFilledPolygon(), gdImageGif(), gdImageInterlace(), gdImageLine(), gdImageSetBrush(), gdImageSetStyle(), gdImageString(), gdImageStringUp(), gdImageSX, gdImageSY, gdStyledBrushed, gdPoint::x, and gdPoint::y.
Referenced by toMain::editDisable(), toMain::editEnable(), main(), and toMain::setEditWidget().
00007 { 00008 /* Input and output files */ 00009 FILE *in; 00010 FILE *out; 00011 00012 /* Input and output images */ 00013 gdImagePtr im_in, im_out; 00014 00015 /* Brush image */ 00016 gdImagePtr brush; 00017 00018 /* Color indexes */ 00019 int white; 00020 int blue; 00021 int red; 00022 int green; 00023 00024 /* Points for polygon */ 00025 gdPoint points[3]; 00026 00027 /* Create output image, 128 by 128 pixels. */ 00028 im_out = gdImageCreate(128, 128); 00029 00030 /* First color allocated is background. */ 00031 white = gdImageColorAllocate(im_out, 255, 255, 255); 00032 00033 /* Set transparent color. */ 00034 gdImageColorTransparent(im_out, white); 00035 00036 /* Try to load demoin.gif and paste part of it into the 00037 output image. */ 00038 00039 in = fopen("demoin.gif", "rb"); 00040 if (!in) { 00041 fprintf(stderr, "Can't load source image; this demo\n"); 00042 fprintf(stderr, "is much more impressive if demoin.gif\n"); 00043 fprintf(stderr, "is available.\n"); 00044 im_in = 0; 00045 } else { 00046 im_in = gdImageCreateFromGif(in); 00047 fclose(in); 00048 /* Now copy, and magnify as we do so */ 00049 gdImageCopyResized(im_out, im_in, 00050 16, 16, 0, 0, 96, 96, 127, 127); 00051 } 00052 red = gdImageColorAllocate(im_out, 255, 0, 0); 00053 green = gdImageColorAllocate(im_out, 0, 255, 0); 00054 blue = gdImageColorAllocate(im_out, 0, 0, 255); 00055 /* Rectangle */ 00056 gdImageLine(im_out, 8, 8, 120, 8, green); 00057 gdImageLine(im_out, 120, 8, 120, 120, green); 00058 gdImageLine(im_out, 120, 120, 8, 120, green); 00059 gdImageLine(im_out, 8, 120, 8, 8, green); 00060 /* Circle */ 00061 gdImageArc(im_out, 64, 64, 30, 10, 0, 360, blue); 00062 /* Arc */ 00063 gdImageArc(im_out, 64, 64, 20, 20, 45, 135, blue); 00064 /* Flood fill */ 00065 gdImageFill(im_out, 4, 4, blue); 00066 /* Polygon */ 00067 points[0].x = 32; 00068 points[0].y = 0; 00069 points[1].x = 0; 00070 points[1].y = 64; 00071 points[2].x = 64; 00072 points[2].y = 64; 00073 gdImageFilledPolygon(im_out, points, 3, green); 00074 /* Brush. A fairly wild example also involving a line style! */ 00075 if (im_in) { 00076 int style[8]; 00077 brush = gdImageCreate(8, 8); 00078 gdImageCopyResized(brush, im_in, 00079 0, 0, 0, 0, 00080 gdImageSX(brush), gdImageSY(brush), 00081 gdImageSX(im_in), gdImageSY(im_in)); 00082 gdImageSetBrush(im_out, brush); 00083 /* With a style, so they won't overprint each other. 00084 Normally, they would, yielding a fat-brush effect. */ 00085 style[0] = 0; 00086 style[1] = 0; 00087 style[2] = 0; 00088 style[3] = 0; 00089 style[4] = 0; 00090 style[5] = 0; 00091 style[6] = 0; 00092 style[7] = 1; 00093 gdImageSetStyle(im_out, style, 8); 00094 /* Draw the styled, brushed line */ 00095 gdImageLine(im_out, 0, 127, 127, 0, gdStyledBrushed); 00096 } 00097 /* Text */ 00098 gdImageString(im_out, gdFontGiant, 16, 16, (unsigned char *)"hi", red); 00099 gdImageStringUp(im_out, gdFontSmall, 32, 32, (unsigned char *)"hi", red); 00100 /* Make output image interlaced (allows "fade in" in some viewers, 00101 and in the latest web browsers) */ 00102 gdImageInterlace(im_out, 1); 00103 out = fopen("demoout.gif", "wb"); 00104 /* Write GIF */ 00105 gdImageGif(im_out, out); 00106 fclose(out); 00107 gdImageDestroy(im_out); 00108 if (im_in) { 00109 gdImageDestroy(im_in); 00110 } 00111 return 0; 00112 }
1.5.1