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 <cstdlib>
15#include <string>
16#include <iostream>
17
18using namespace std;
19
20using namespace Magick;
21
22int main( int /*argc*/, char ** argv)
23{
24
25 // Initialize ImageMagick install location for Windows
26 MagickPlusPlusGenesis genesis(*argv);
27
28 try {
29
30 string srcdir("");
31 if(getenv("SRCDIR") != 0)
32 srcdir = getenv("SRCDIR");
33
34 //
35 // Create a 300x300 white canvas.
36 //
37 Image image( "300x300", "white" );
38
39 //
40 // Draw texture-filled polygon
41 //
42 // Polygon list
43 std::vector<Coordinate> poly_coord;
44 poly_coord.push_back( Coordinate(30,30) );
45 poly_coord.push_back( Coordinate(100,10) );
46 poly_coord.push_back( Coordinate(190,290) );
47 poly_coord.push_back( Coordinate(30,290) );
48
49 Image texture( srcdir + "tile.miff" );
50 image.fillPattern( texture );
51 image.draw( DrawablePolygon( poly_coord ) );
52 texture.isValid( false );
53 image.fillPattern( texture ); // Unset texture
54
55 //
56 // Draw filled ellipse with black border, and red fill color
57 //
58 image.strokeColor( "black" );
59 image.fillColor( "red" );
60 image.strokeWidth( 5 );
61 image.draw( DrawableEllipse( 100,100, 50,75, 0,360 ) );
62 image.fillColor( Color() ); // Clear out fill color
63
64 //
65 // Draw ellipse, and polygon, with black stroke, strokeWidth of 5
66 //
67 image.strokeColor( "black" );
68 image.strokeWidth( 5 );
69 vector<Drawable> drawlist;
70
71 // Add polygon to list
72 poly_coord.clear();
73 poly_coord.push_back( Coordinate(30,30) );
74 poly_coord.push_back( Coordinate(100,10) );
75 poly_coord.push_back( Coordinate(190,290) );
76 poly_coord.push_back( Coordinate(30,290) );
77 drawlist.push_back( DrawablePolygon( poly_coord ) );
78 image.draw( drawlist );
79
80 //
81 // Floodfill object with blue
82 //
83 image.colorFuzz( 0.5*QuantumRange );
84 image.floodFillColor( "+132+62", "blue" );
85
86 //
87 // Draw text
88 //
89 image.strokeColor(Color());
90 image.fillColor( "red" );
91 if (getenv("MAGICK_FONT") != 0)
92 image.font(string(getenv("MAGICK_FONT")));
93 image.fontPointsize( 18 );
94#if defined(MAGICKCORE_FREETYPE_DELEGATE)
95 image.annotate( "Hello world!", "+150+20" );
96#endif
97
98 image.fillColor( "blue" );
99 image.fontPointsize( 14 );
100#if defined(MAGICKCORE_FREETYPE_DELEGATE)
101 image.annotate( "Goodbye cruel world!", "+150+38" );
102#endif
103
104 image.fillColor( "black" );
105 image.fontPointsize( 14 );
106#if defined(MAGICKCORE_FREETYPE_DELEGATE)
107 image.annotate( "I'm climbing the wall!", "+280+120",
108 NorthWestGravity, 90.0 );
109#endif
110 //image.display();
111 //
112 // Write image.
113 //
114
115 cout << "Writing image \"shapes_out.miff\" ..." << endl;
116 image.depth( 8 );
117 image.compressType( RLECompression );
118 image.write( "shapes_out.miff" );
119
120 // cout << "Display image..." << endl;
121 // image.display( );
122
123 }
124 catch( exception &error_ )
125 {
126 cout << "Caught exception: " << error_.what() << endl;
127 return 1;
128 }
129
130 return 0;
131}