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