Magick++  7.0.10
shapes.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 // GD/PerlMagick example using Magick++ methods.
6 //
7 // Concept and algorithms lifted from PerlMagick demo script
8 //
9 
10 #include <Magick++.h>
11 #include <string>
12 #include <iostream>
13 
14 using namespace std;
15 
16 using namespace Magick;
17 
18 int main( int /*argc*/, char ** argv)
19 {
20 
21  // Initialize ImageMagick install location for Windows
22  InitializeMagick(*argv);
23 
24  try {
25 
26  string srcdir("");
27  if(getenv("SRCDIR") != 0)
28  srcdir = getenv("SRCDIR");
29 
30  //
31  // Create a 300x300 white canvas.
32  //
33  Image image( "300x300", "white" );
34 
35  //
36  // Draw texture-filled polygon
37  //
38  // Polygon list
39  std::vector<Coordinate> poly_coord;
40  poly_coord.push_back( Coordinate(30,30) );
41  poly_coord.push_back( Coordinate(100,10) );
42  poly_coord.push_back( Coordinate(190,290) );
43  poly_coord.push_back( Coordinate(30,290) );
44 
45  Image texture( srcdir + "tile.miff" );
46  image.fillPattern( texture );
47  image.draw( DrawablePolygon( poly_coord ) );
48  texture.isValid( false );
49  image.fillPattern( texture ); // Unset texture
50 
51  //
52  // Draw filled ellipse with black border, and red fill color
53  //
54  image.strokeColor( "black" );
55  image.fillColor( "red" );
56  image.strokeWidth( 5 );
57  image.draw( DrawableEllipse( 100,100, 50,75, 0,360 ) );
58  image.fillColor( Color() ); // Clear out fill color
59 
60  //
61  // Draw ellipse, and polygon, with black stroke, strokeWidth of 5
62  //
63  image.strokeColor( "black" );
64  image.strokeWidth( 5 );
65  vector<Drawable> drawlist;
66 
67  // Add polygon to list
68  poly_coord.clear();
69  poly_coord.push_back( Coordinate(30,30) );
70  poly_coord.push_back( Coordinate(100,10) );
71  poly_coord.push_back( Coordinate(190,290) );
72  poly_coord.push_back( Coordinate(30,290) );
73  drawlist.push_back( DrawablePolygon( poly_coord ) );
74  image.draw( drawlist );
75 
76  //
77  // Floodfill object with blue
78  //
79  image.colorFuzz( 0.5*QuantumRange );
80  image.floodFillColor( "+132+62", "blue" );
81 
82  //
83  // Draw text
84  //
85  image.strokeColor(Color());
86  image.fillColor( "red" );
87  if (getenv("MAGICK_FONT") != 0)
88  image.font(string(getenv("MAGICK_FONT")));
89  image.fontPointsize( 18 );
90 #if MAGICKCORE_FREETYPE_DELEGATE
91  image.annotate( "Hello world!", "+150+20" );
92 #endif
93 
94  image.fillColor( "blue" );
95  image.fontPointsize( 14 );
96 #if MAGICKCORE_FREETYPE_DELEGATE
97  image.annotate( "Goodbye cruel world!", "+150+38" );
98 #endif
99 
100  image.fillColor( "black" );
101  image.fontPointsize( 14 );
102 #if MAGICKCORE_FREETYPE_DELEGATE
103  image.annotate( "I'm climbing the wall!", "+280+120",
104  NorthWestGravity, 90.0 );
105 #endif
106  //image.display();
107  //
108  // Write image.
109  //
110 
111  cout << "Writing image \"shapes_out.miff\" ..." << endl;
112  image.depth( 8 );
113  image.compressType( RLECompression );
114  image.write( "shapes_out.miff" );
115 
116  // cout << "Display image..." << endl;
117  // image.display( );
118 
119  }
120  catch( exception &error_ )
121  {
122  cout << "Caught exception: " << error_.what() << endl;
123  return 1;
124  }
125 
126  return 0;
127 }
class MagickPPExport Color
Definition: Color.h:16
void annotate(const std::string &text_, const Geometry &location_)
Definition: Image.cpp:1845
int main(int, char **argv)
Definition: shapes.cpp:18
STL namespace.
void write(Blob *blob_)
Definition: Image.cpp:4880
void strokeWidth(const double strokeWidth_)
Definition: Image.cpp:1494
void strokeColor(const Color &strokeColor_)
Definition: Image.cpp:1390
void colorFuzz(const double fuzz_)
Definition: Image.cpp:525
void font(const std::string &font_)
Definition: Image.cpp:850
void fontPointsize(const double pointSize_)
Definition: Image.cpp:872
void fillPattern(const Image &fillPattern_)
Definition: Image.cpp:806
void fillColor(const Color &fillColor_)
Definition: Image.cpp:784
void draw(const Drawable &drawable_)
Definition: Image.cpp:2785
void isValid(const bool isValid_)
Definition: Image.cpp:1074
Definition: Blob.h:15
void floodFillColor(const Geometry &point_, const Color &fillColor_, const bool invert_=false)
Definition: Image.cpp:3031
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:43
void depth(const size_t depth_)
Definition: Image.cpp:691
void compressType(const CompressionType compressType_)
Definition: Image.cpp:628