root/ImageMagick/trunk/Magick++/demo/detrans.cpp

Revision 1, 1.2 KB (checked in by cristy, 7 months ago)


Line 
1//
2// Replace transparency in an image with a solid color using Magick++
3//
4// Useful to see how a transparent image looks on a particular
5// background color, or to create a similar looking effect without
6// transparency.
7//
8// Copyright Bob Friesenhahn, 2000
9//
10// Usage: detrans color file...
11//
12
13#include <Magick++.h>
14#include <iostream>
15using namespace std;
16using namespace Magick;
17int main(int argc,char **argv)
18{
19  if ( argc < 3 )
20    {
21      cout << "Usage: " << argv[0] << " background_color file..." << endl;
22      exit( 1 );
23    }
24
25  // Initialize ImageMagick install location for Windows
26  InitializeMagick(*argv);
27
28  {
29    Color color;
30    try {
31      color = Color(argv[1]);
32    }
33    catch ( Exception error_ )
34      {
35        cout << error_.what() << endl;
36        cout.flush();
37        exit(1);
38      }
39
40    char **arg = &argv[2];
41    while ( *arg )
42      {
43        string fname(*arg);
44        try {
45          Image overlay( fname );
46          Image base( overlay.size(), color );
47          base.composite( overlay, 0, 0, OverCompositeOp );
48          base.matte( false );
49          base.write( fname );
50        }
51        catch( Exception &error_ )
52          {
53            cout << error_.what() << endl;
54          }
55        ++arg;
56      }
57  }
58
59  return 0;
60}
Note: See TracBrowser for help on using the browser.