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