Magick++ 7.1.0

piddle.cpp
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2002, 2003
4 //
5 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
6 // dedicated to making software imaging solutions freely available.
7 //
8 // PerlMagick "piddle" demo re-implemented using Magick++ methods.
9 // The PerlMagick "piddle" demo is written by Cristy
10 //
11
12 #include <Magick++.h>
13 #include <string>
14 #include <iostream>
15
16 using namespace std;
17
18 using namespace Magick;
19
20 int main( int /*argc*/, char ** argv)
21 {
22
23 // Initialize ImageMagick install location for Windows
24 InitializeMagick(*argv);
25
26 try {
27
28 string srcdir("");
29 if(getenv("SRCDIR") != 0)
30 srcdir = getenv("SRCDIR");
31
32 //
33 // Create a 300x300 white canvas.
34 //
35 Image image( "300x300", "white" );
36
37 // Drawing list
38 std::vector<Magick::Drawable> drawList;
39
40 // Start drawing by pushing a drawing context with specified
41 // viewbox size
42 drawList.push_back(DrawablePushGraphicContext());
43 drawList.push_back(DrawableViewbox(0,0,image.columns(),image.rows()));
44
45 //
46 // Draw blue grid
47 //
48 drawList.push_back(DrawableStrokeColor("#ccf"));
49 for ( int i=0; i < 300; i += 10 )
50 {
51 drawList.push_back(DrawableLine(i,0, i,300));
52 drawList.push_back(DrawableLine(0,i, 300,i));
53 }
54
55 //
56 // Draw rounded rectangle.
57 //
58 drawList.push_back(DrawableFillColor("blue"));
59 drawList.push_back(DrawableStrokeColor("red"));
60 drawList.push_back(DrawableRoundRectangle(15,15, 70,70, 10,10));
61
62 drawList.push_back(DrawableFillColor("blue"));
63 drawList.push_back(DrawableStrokeColor("maroon"));
64 drawList.push_back(DrawableStrokeWidth(4));
65 drawList.push_back(DrawableRoundRectangle(15,15, 70,70, 10,10));
66
67 //
68 // Draw curve.
69 //
70 {
71 drawList.push_back(DrawableStrokeColor("black"));
72 drawList.push_back(DrawableStrokeWidth(4));
73 drawList.push_back(DrawableFillColor(Color()));
74
75 std::vector<Magick::Coordinate> points;
76 points.push_back(Coordinate(20,20));
77 points.push_back(Coordinate(100,50));
78 points.push_back(Coordinate(50,100));
79 points.push_back(Coordinate(160,160));
80 drawList.push_back(DrawableBezier(points));
81 }
82
83 //
84 // Draw line
85 //
86 {
87 const double dash_array[] = {4.0, 3.0, 0.0};
88 drawList.push_back(DrawableStrokeDashArray(dash_array));
89 drawList.push_back(DrawableStrokeColor("red"));
90 drawList.push_back(DrawableStrokeWidth(1));
91 drawList.push_back(DrawableLine(10,200, 54,182));
92 drawList.push_back(DrawableStrokeDashArray((double *) 0));
93 }
94
95 //
96 // Draw arc within a circle.
97 //
98 drawList.push_back(DrawableStrokeColor("black"));
99 drawList.push_back(DrawableFillColor("yellow"));
100 drawList.push_back(DrawableStrokeWidth(4));
101 drawList.push_back(DrawableCircle(160,70, 200,70));
102
103 drawList.push_back(DrawableStrokeColor("black"));
104 drawList.push_back(DrawableFillColor("blue"));
105 drawList.push_back(DrawableStrokeWidth(4));
106 {
107 std::vector<VPath> path;
108 path.push_back(PathMovetoAbs(Coordinate(160,70)));
109 path.push_back(PathLinetoVerticalRel(-40));
110 path.push_back(PathArcRel(PathArcArgs(40,40, 0, 0, 0, -40,40)));
111 path.push_back(PathClosePath());
112 drawList.push_back(DrawablePath(path));
113 }
114
115 //
116 // Draw pentogram.
117 //
118 {
119 drawList.push_back(DrawableStrokeColor("red"));
120 drawList.push_back(DrawableFillColor("LimeGreen"));
121 drawList.push_back(DrawableStrokeWidth(3));
122
123 std::vector<Magick::Coordinate> points;
124 points.push_back(Coordinate(160,120));
125 points.push_back(Coordinate(130,190));
126 points.push_back(Coordinate(210,145));
127 points.push_back(Coordinate(110,145));
128 points.push_back(Coordinate(190,190));
129 points.push_back(Coordinate(160,120));
130 drawList.push_back(DrawablePolygon(points));
131 }
132
133 //
134 // Draw rectangle.
135 //
136 drawList.push_back(DrawableStrokeWidth(5));
137 drawList.push_back(DrawableFillColor(Color())); // No fill
138 drawList.push_back(DrawableStrokeColor("yellow"));
139 drawList.push_back(DrawableLine(200,260, 200,200));
140 drawList.push_back(DrawableLine(200,200, 260,200));
141 drawList.push_back(DrawableStrokeColor("red"));
142 drawList.push_back(DrawableLine(260,200, 260,260));
143 drawList.push_back(DrawableStrokeColor("green"));
144 drawList.push_back(DrawableLine(200,260, 260,260));
145
146 //
147 // Draw text.
148 //
149 #if MAGICKCORE_FREETYPE_DELEGATE
150 if (getenv("MAGICK_FONT") != 0)
151 drawList.push_back(DrawableFont(string(getenv("MAGICK_FONT"))));
152 drawList.push_back(DrawableFillColor("green"));
153 drawList.push_back(DrawableStrokeColor(Color())); // unset color
154 drawList.push_back(DrawablePointSize(24));
155 drawList.push_back(DrawableTranslation(30,140));
156 drawList.push_back(DrawableRotation(45.0));
157 drawList.push_back(DrawableText(0,0,"This is a test!"));
158 #endif
159
160 // Finish drawing by popping back to base context.
161 drawList.push_back(DrawablePopGraphicContext());
162
163 // Draw everything using completed drawing list
164 // image.debug(true);
165 image.draw(drawList);
166
167 // image.write( "piddle.mvg" );
168
169 cout << "Writing image \"piddle_out.miff\" ..." << endl;
170 image.depth( 8 );
171 image.compressType( RLECompression );
172 image.write( "piddle_out.miff" );
173 cout << "Writing MVG metafile \"piddle_out.mvg\" ..." << endl;
174 image.write( "piddle_out.mvg" );
175
176 // cout << "Display image..." << endl;
177 // image.display( );
178
179 }
180 catch( exception &error_ )
181 {
182 cout << "Caught exception: " << error_.what() << endl;
183 return 1;
184 }
185
186 return 0;
187 }
Magick::Color
class MagickPPExport Color
Definition: Color.h:18
Magick::DrawableTranslation
Definition: Drawable.h:2251
main
int main(int, char **argv)
Definition: piddle.cpp:20
Magick::DrawablePointSize
Definition: Drawable.h:1244
Magick::DrawableFont
Definition: Drawable.h:1054
std
STL namespace.
Magick::Image::write
void write(Blob *blob_)
Definition: Image.cpp:4896
Magick::DrawableStrokeDashArray
Definition: Drawable.h:1721
Magick++.h
Magick::PathClosePath
Definition: Drawable.h:2517
Magick::DrawableLine
Definition: Drawable.h:1121
Magick::Coordinate
Definition: Drawable.h:48
Magick::PathArcArgs
Definition: Drawable.h:2356
Magick::DrawableText
Definition: Drawable.h:2002
Magick::Image::draw
void draw(const Drawable &drawable_)
Definition: Image.cpp:2798
Magick::DrawableFillColor
Definition: Drawable.h:936
Magick::DrawableRotation
Definition: Drawable.h:1464
Magick::DrawableCircle
Definition: Drawable.h:606
Magick::DrawablePath
Definition: Drawable.h:1184
Magick::DrawableBezier
Definition: Drawable.h:446
Magick::PathMovetoAbs
Definition: Drawable.h:3089
Magick::DrawableRoundRectangle
Definition: Drawable.h:1493
Magick::Image::rows
size_t rows(void) const
Definition: Image.cpp:1352
Magick::Image::columns
size_t columns(void) const
Definition: Image.cpp:590
Magick::DrawableStrokeWidth
Definition: Drawable.h:1973
Magick::DrawablePushGraphicContext
Definition: Drawable.h:1334
Magick
Definition: Blob.h:17
Magick::DrawablePopGraphicContext
Definition: Drawable.h:1313
Magick::DrawableStrokeColor
Definition: Drawable.h:1912
Magick::InitializeMagick
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:45
Magick::PathLinetoVerticalRel
Definition: Drawable.h:3059
Magick::PathArcRel
Definition: Drawable.h:2493
Magick::DrawablePolygon
Definition: Drawable.h:1273
Magick::Image::depth
void depth(const size_t depth_)
Definition: Image.cpp:693
Magick::Image
Definition: Image.h:55
Magick::DrawableViewbox
Definition: Drawable.h:2291
Magick::Image::compressType
void compressType(const CompressionType compressType_)
Definition: Image.cpp:630