天天看點

Visual Studio2013下Magick++配置方法 一、下載下傳源碼 二、配置configure.exe 三、用configure.exe生成.sln檔案 四、編譯項目。 五、使用

ImageMagick是一個圖檔編輯的跨平台開源庫,可以讀寫各種類型的圖檔(包括svg格式的矢量圖)并對其進行處理。本文将介紹Win10平台下用源碼編譯ImageMagick庫的流程,主要支援Visual Studio 2013的調用。

下載下傳後解壓,找到\ImageMagick-7.0.2-9\VisualMagick\configure檔案夾(注意,隻有windows平台下的源碼才包含VisualMagick檔案夾,如果找不到這個檔案夾可能是下載下傳錯了),如果該檔案夾下沒有configure.exe檔案,則用VS打開configure.sln生成configure.exe檔案。

打開configure.exe,

Visual Studio2013下Magick++配置方法 一、下載下傳源碼 二、配置configure.exe 三、用configure.exe生成.sln檔案 四、編譯項目。 五、使用

單擊下一步。

Visual Studio2013下Magick++配置方法 一、下載下傳源碼 二、配置configure.exe 三、用configure.exe生成.sln檔案 四、編譯項目。 五、使用

來到配置頁面,這裡需要注意:

第一欄build type setup,根據需要選擇動态連結庫還是靜态連結庫;

第二欄裡面,如果是生成x64平台下的庫檔案,就勾選Build 64-bit distribution;選擇正确的VS版本(Visual Studio Version),我是用的是VS2013,是以選擇了2013;建議勾選Include all demo, test, appl, and contrib director。

然後完成,生成項目。

接下來前往父目錄(\ImageMagick-7.0.2-9\VisualMagick)打開Visual*.sln,編譯生成項目。

生成的過程中可能會因為編碼問題遇到幾個error:

項目CORE_pango,提示常量中包含換行符,找到錯誤的位置,在字元串最後添加一個空格即可;這是因為非ASCII碼後面直接跟的字元被忽略掉了。

弄完這幾個bug就差不多可以編譯成功了。

注意:最好将debug和release都編譯一遍,這兩者生成的.lib和.dll檔案分别為:*DB*./*RL*.

編譯好之後,将\VisualMagick\bin目錄下的.dll動态連結庫拷貝到C:\Windows\System32目錄下,建立一個Visual Studio項目,添加

包含目錄:

$(ImageMagickPath)\ImageMagick  

$(ImageMagickPath)\ImageMagick\Magick++\lib  

庫目錄:

$(ImageMagickPath)\VisualMagick\lib  

debug下添加附加依賴項:

CORE_DB_Magick++_.lib  

CORE_DB_MagickCore_.lib  

CORE_DB_MagickWand_.lib  

release下添加附加依賴項:

CORE_RL_Magick++_.lib  

CORE_RL_MagickCore_.lib  

CORE_RL_MagickWand_.lib  

#include <Magick++.h>   

#include <iostream>   

using namespace std;   

using namespace Magick;   

int main(int argc,char **argv)   

{   

  InitializeMagick(*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( "logo:" );  

    // 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( "logo.png" );   

  }   

  catch( Exception &error_ )   

    {   

      cout << "Caught exception: " << error_.what() << endl;   

      return 1;   

    }   

  return 0;   

}  

如果這個項目運作後提示

UnableToOpenConfigureFile `magic.xml'  

的話,可以把\bin\magic.xml複制到exe檔案所在的檔案夾。這個問題貌似是源碼的一個bug,加載*.xml的時候路徑錯誤。尚未找到其他解決方案。如果有更好的辦法歡迎留言。

到此,就把ImageMagick配置好了。

參考:

<a href="http://blog.csdn.net/fksec/article/details/36008343" target="_blank">http://blog.csdn.net/fksec/article/details/36008343</a>

<a href="http://qingqingzjin.blog.163.com/blog/static/1881032672013917103716344/" target="_blank">http://qingqingzjin.blog.163.com/blog/static/1881032672013917103716344/</a>

<dl></dl>

<dt>頂</dt>

<dd>0</dd>

<dl><dt>踩</dt></dl>