Visual Studio2013下Magick++配置方法

声明:本文系作者原创,如需转载请保持文章完整并注明出处(http://blog.csdn.net/u010281174/article/details/52224829)。

ImageMagick是一个图片编辑的跨平台开源库,可以读写各种类型的图片(包括svg格式的矢量图)并对其进行处理。本文将介绍Win10平台下用源码编译ImageMagick库的流程,主要支持Visual Studio 2013的调用。

一、下载源码

首先前往官网下载源码。注意是下载源码,不是可执行文件。(http://imagemagick.org/script/install-source.php#windows)选择Install from Windows Source下的download。

二、配置configure.exe

下载后解压,找到ImageMagick-7.0.2-9VisualMagickconfigure文件夹(注意,只有windows平台下的源码才包含VisualMagick文件夹,如果找不到这个文件夹可能是下载错了),如果该文件夹下没有configure.exe文件,则用VS打开configure.sln生成configure.exe文件。

三、用configure.exe生成.sln文件

打开configure.exe,


单击下一步。


来到配置页面,这里需要注意:

  1. 第一栏build type setup,根据需要选择动态链接库还是静态链接库;
  2. 第二栏里面,如果是生成x64平台下的库文件,就勾选Build 64-bit distribution;选择正确的VS版本(Visual Studio Version),我是用的是VS2013,因此选择了2013;建议勾选Include all demo, test, appl, and contrib director。

然后完成,生成项目。

四、编译项目。

接下来前往父目录(ImageMagick-7.0.2-9VisualMagick)打开Visual*.sln,编译生成项目。

生成的过程中可能会因为编码问题遇到几个error:

  1. 项目CORE_pango,提示常量中包含换行符,找到错误的位置,在字符串最后添加一个空格即可;这是因为非ASCII码后面直接跟的字符被忽略掉了。
  2. afstyles.h文件中line100有个错误,这个错误同样是因为编码问题,但是这个问题的根源来自于afscript.h文件,其中很多/**/注释中间是非ASCII字符,将这些注释后面(*/前面)添加一个空格即可解决问题。这个bug隐藏的很深,思路来源自http://savannah.nongnu.org/bugs/?48126,感谢这位作者!

弄完这几个bug就差不多可以编译成功了。

注意:最好将debug和release都编译一遍,这两者生成的.lib和.dll文件分别为:*DB*./*RL*.

五、使用

编译好之后,将VisualMagickin目录下的.dll动态链接库拷贝到C:WindowsSystem32目录下,新建一个Visual Studio项目,添加

包含目录:

[plain] view plain copy
 
  1. $(ImageMagickPath)ImageMagick  
  2. $(ImageMagickPath)ImageMagickMagick++lib  


库目录:

[plain] view plain copy
 
  1. $(ImageMagickPath)VisualMagicklib  

debug下添加附加依赖项:

[plain] view plain copy
 
  1. CORE_DB_Magick++_.lib  
  2. CORE_DB_MagickCore_.lib  
  3. CORE_DB_MagickWand_.lib  

release下添加附加依赖项:

[plain] view plain copy
 
  1. CORE_RL_Magick++_.lib  
  2. CORE_RL_MagickCore_.lib  
  3. CORE_RL_MagickWand_.lib  

添加一个cpp文件,用官网给的示例(http://imagemagick.org/script/magick++.php):

[cpp] view plain copy
 
  1. #include <Magick++.h>   
  2. #include <iostream>   
  3.   
  4. using namespace std;   
  5. using namespace Magick;   
  6.   
  7. int main(int argc,char **argv)   
  8. {   
  9.   InitializeMagick(*argv);  
  10.   
  11.   // Construct the image object. Seperating image construction from the   
  12.   // the read operation ensures that a failure to read the image file   
  13.   // doesn't render the image object useless.   
  14.   Image image;  
  15.   try {   
  16.     // Read a file into image object   
  17.     image.read( "logo:" );  
  18.   
  19.     // Crop the image to specified size (width, height, xOffset, yOffset)  
  20.     image.crop( Geometry(100,100, 100, 100) );  
  21.   
  22.     // Write the image to a file   
  23.     image.write( "logo.png" );   
  24.   }   
  25.   catch( Exception &error_ )   
  26.     {   
  27.       cout << "Caught exception: " << error_.what() << endl;   
  28.       return 1;   
  29.     }   
  30.   return 0;   
  31. }  

如果这个项目运行后提示

[plain] view plain copy
 
  1. UnableToOpenConfigureFile `magic.xml'  

的话,可以把inmagic.xml复制到exe文件所在的文件夹。这个问题貌似是源码的一个bug,加载*.xml的时候路径错误。尚未找到其他解决方案。如果有更好的办法欢迎留言。

到此,就把ImageMagick配置好了。

参考:

http://blog.csdn.net/fksec/article/details/36008343

http://qingqingzjin.blog.163.com/blog/static/1881032672013917103716344/

 
0
原文地址:https://www.cnblogs.com/lidabo/p/6930227.html