Home | History | Annotate | Download | only in demo
      1 //
      2 // Magick++ demo to generate a simple text button
      3 //
      4 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2003
      5 //
      6 
      7 #include <Magick++.h>
      8 #include <string>
      9 #include <iostream>
     10 
     11 using namespace std;
     12 
     13 using namespace Magick;
     14 
     15 int main( int /*argc*/, char ** argv)
     16 {
     17 
     18   // Initialize ImageMagick install location for Windows
     19   InitializeMagick(*argv);
     20 
     21   try {
     22 
     23     string srcdir("");
     24     if(getenv("SRCDIR") != 0)
     25       srcdir = getenv("SRCDIR");
     26 
     27     //
     28     // Options
     29     //
     30 
     31     string backGround = "xc:#CCCCCC"; // A solid color
     32 
     33     // Color to use for decorative border
     34     Color border = "#D4DCF3";
     35 
     36     // Button size
     37     string buttonSize = "120x20";
     38 
     39     // Button background texture
     40     string buttonTexture = "granite:";
     41 
     42     // Button text
     43     string text = "Button Text";
     44 
     45     // Button text color
     46     string textColor = "red";
     47 
     48     // Font point size
     49     int fontPointSize = 16;
     50 
     51     //
     52     // Magick++ operations
     53     //
     54 
     55     Image button;
     56 
     57     // Set button size
     58     button.size( buttonSize );
     59 
     60     // Read background image
     61     button.read( backGround );
     62 
     63     // Set background to buttonTexture
     64     Image backgroundTexture( buttonTexture );
     65     button.texture( backgroundTexture );
     66 
     67     // Add some text
     68     button.fillColor( textColor );
     69     button.fontPointsize( fontPointSize );
     70     button.annotate( text, CenterGravity );
     71 
     72     // Add a decorative frame
     73     button.borderColor( border );
     74     button.frame( "6x6+3+3" );
     75 
     76     button.depth( 8 );
     77 
     78     // Quantize to desired colors
     79     // button.quantizeTreeDepth(8);
     80     button.quantizeDither(false);
     81     button.quantizeColors(64);
     82     button.quantize();
     83 
     84     // Save to file
     85     cout << "Writing to \"button_out.miff\" ..." << endl;
     86     button.compressType( RLECompression );
     87     button.write("button_out.miff");
     88 
     89     // Display on screen
     90     // button.display();
     91 
     92   }
     93   catch( exception &error_ )
     94     {
     95       cout << "Caught exception: " << error_.what() << endl;
     96       return 1;
     97     }
     98 
     99   return 0;
    100 }
    101