Magick++: button.cpp Source File

Magick++ 7.1.0

button.cpp
Go to the documentation of this file.
1 //
2 // Magick++ demo to generate a simple text button
3 //
4 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2003
5 //
6 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
7 // dedicated to making software imaging solutions freely available.
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 // Options
32 //
33
34 string backGround = "xc:#CCCCCC"; // A solid color
35
36 // Color to use for decorative border
37 Color border = "#D4DCF3";
38
39 // Button size
40 string buttonSize = "120x20";
41
42 // Button background texture
43 string buttonTexture = "granite:";
44
45 // Button text
46 string text = "Button Text";
47
48 // Button text color
49 string textColor = "red";
50
51 // Font point size
52 int fontPointSize = 16;
53
54 //
55 // Magick++ operations
56 //
57
58 Image button;
59
60 // Set button size
61 button.size( buttonSize );
62
63 // Read background image
64 button.read( backGround );
65
66 // Set background to buttonTexture
67 Image backgroundTexture( buttonTexture );
68 button.texture( backgroundTexture );
69
70 #if MAGICKCORE_FREETYPE_DELEGATE
71 // Add some text
72 button.fillColor( textColor );
73 button.fontPointsize( fontPointSize );
74 if (getenv("MAGICK_FONT") != 0)
75 button.font(string(getenv("MAGICK_FONT")));
76 button.annotate( text, CenterGravity );
77 #endif
78
79 // Add a decorative frame
80 button.borderColor( border );
81 button.frame( "6x6+3+3" );
82
83 button.depth( 8 );
84
85 // Quantize to desired colors
86 // button.quantizeTreeDepth(8);
87 button.quantizeDither(false);
88 button.quantizeColors(64);
89 button.quantize();
90
91 // Save to file
92 cout << "Writing to \"button_out.miff\" ..." << endl;
93 button.compressType( RLECompression );
94 button.write("button_out.miff");
95
96 // Display on screen
97 // button.display();
98
99 }
100 catch( exception &error_ )
101 {
102 cout << "Caught exception: " << error_.what() << endl;
103 return 1;
104 }
105
106 return 0;
107 }
Magick::Image::annotate
void annotate(const std::string &text_, const Geometry &location_)
Definition: Image.cpp:1858
std
STL namespace.
Magick::Image::write
void write(Blob *blob_)
Definition: Image.cpp:4896
Magick++.h
Magick::Image::quantize
void quantize(const bool measureError_=false)
Definition: Image.cpp:3994
Magick::Image::read
void read(const Blob &blob_)
Definition: Image.cpp:4038
Magick::Image::frame
void frame(const Geometry &geometry_=frameGeometryDefault)
Definition: Image.cpp:3162
Magick::Image::borderColor
void borderColor(const Color &color_)
Definition: Image.cpp:429
Magick::Image::font
void font(const std::string &font_)
Definition: Image.cpp:852
Magick::Image::fontPointsize
void fontPointsize(const double pointSize_)
Definition: Image.cpp:874
Magick::Image::texture
void texture(const Image &texture_)
Definition: Image.cpp:4642
Magick::Image::fillColor
void fillColor(const Color &fillColor_)
Definition: Image.cpp:786
Magick::Image::size
void size(const Geometry &geometry_)
Definition: Image.cpp:1379
Magick::Color
Definition: Color.h:36
Magick::Image::quantizeColors
void quantizeColors(const size_t colors_)
Definition: Image.cpp:1260
Magick
Definition: Blob.h:17
main
int main(int, char **argv)
Definition: button.cpp:18
Magick::InitializeMagick
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:45
Magick::Image::quantizeDither
void quantizeDither(const bool ditherFlag_)
Definition: Image.cpp:1283
Magick::Image::depth
void depth(const size_t depth_)
Definition: Image.cpp:693
Magick::Image
Definition: Image.h:55
Magick::Image::compressType
void compressType(const CompressionType compressType_)
Definition: Image.cpp:630