Magick++ 7.1.1
Loading...
Searching...
No Matches
shapes.cpp
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
17using namespace std;
18
19using namespace Magick;
20
21int 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 defined(MAGICKCORE_FREETYPE_DELEGATE)
94 image.annotate( "Hello world!", "+150+20" );
95#endif
96
97 image.fillColor( "blue" );
98 image.fontPointsize( 14 );
99#if defined(MAGICKCORE_FREETYPE_DELEGATE)
100 image.annotate( "Goodbye cruel world!", "+150+38" );
101#endif
102
103 image.fillColor( "black" );
104 image.fontPointsize( 14 );
105#if defined(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}