« ImageMagickライブラリのビルド | メイン | cygwinで各ドライブへアクセス »

2005年01月13日

ツール開発メモ:: ImageMagickを使う

    

以下は、VC 2003で確認した。
まずはVCを起動し、新規プロジェクトでコンソールアプリのプロジェクトを作った。
そして、インクルードディレクトリに ImageMagick-6.1.8/Magick++/lib とImageMagick-6.1.8 を追加。
ライブラリパスを設定に追加し、ライブラリをフルパスで指定しなくても良いようにした。
ライブラリはいっぱいあって面倒なので、次のように入力して一覧が記述されたテキストファイルを作った。
perl -e "foreach( glob(\"*.lib\") ) { if( /DB/ ) { print $_.\" \"; } }" > DB.txt
Release版も同様に次のようにして一覧テキストを作った。
perl -e "foreach( glob(\"*.lib\") ) { if( /RL/ ) { print $_.\" \"; } }" > RL.txt
で、出力されたテキストファイルからプロジェクトの追加ライブラリにコピペ。
Socket関連も使うようなので、Ws2_32.lib も追加ライブラリに追加。
LIBCMTD を無視するライブラリに追加。
以上で、Magick++を使える環境が整ったはず。
サンプルにあった物とほぼ同じ以下のようなソースをビルド。
#include "stdafx.h"
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;

int _tmain(int argc, _TCHAR* argv[])
{
 // Construct the image object. Seperating image construction from the
 // the read operation ensures that a failure to read the image file
 // doesn't render the image object useless.
 Image image;

 try {
  // Read a file into image object
  image.read( "test.jpg" );

  // Crop the image to specified size (width, height, xOffset, yOffset)
  image.crop( Geometry(100,100, 100, 100) );

  // Write the image to a file
  image.write( "x.jpg" );
 }
 catch( Exception &error_ )
 {
  cout << "Caught exception: " << error_.what() << endl;
  return 1;
 }
 return 0;
}
で、実行したらException。
調べると、どうやら ImageMagick-6.1.8/config/magic.xml が実行ファイルと同じディレクトリに必要なようだ。
magic.xml をコピーし、実行したらうまくいった。
以上でVCからはImageMagickが使えるようになった。
ちなみに、上記コードの実行ファイルのサイズは3.6MB。やはりでかいな。



投稿者 Takenori : 2005年01月13日 05:16




comments powered by Disqus
Total : Today : Yesterday : なかのひと