• 用Codeblocks的MinGW编译CxImage


    1,先到官网下载CxImage,地址:http://www.xdp.it/download.htm 我这里下载的是cximage600_full.

    2,解压,发现里面只有个vc6的工程,没关系,打开Codeblocks,转换工程,成功以后,删除不要的工程CxImageCrtDll和CxImagemfcdll还有demo和demoDll,因为我们是用MinGw编译,这两工程是提供vc6和mfc的dll.

    3,开始编译, 先编译图像库和支持库jasper,jbig,jpeg,libdcr,mng,Tiff,zlib得到对应的lib***.a,新建一个libs文件,把.a拷贝进去

    编译之前先配置cximage,打开 ximacfg.h

    /////////////////////////////////////////////////////////////////////////////
    // CxImage supported features
    #define CXIMAGE_SUPPORT_ALPHA          1
    #define CXIMAGE_SUPPORT_SELECTION      1
    #define CXIMAGE_SUPPORT_TRANSFORMATION 1
    #define CXIMAGE_SUPPORT_DSP            1
    #define CXIMAGE_SUPPORT_LAYERS   1
    #define CXIMAGE_SUPPORT_INTERPOLATION  1
    #define CXIMAGE_SUPPORT_DECODE 1
    #define CXIMAGE_SUPPORT_ENCODE 1 //<vho><T.Peck>
    #define CXIMAGE_SUPPORT_WINDOWS 0
    /////////////////////////////////////////////////////////////////////////////
    // CxImage supported formats
    #define CXIMAGE_SUPPORT_BMP 1
    #define CXIMAGE_SUPPORT_GIF 1
    #define CXIMAGE_SUPPORT_JPG 1
    #define CXIMAGE_SUPPORT_PNG 1
    #define CXIMAGE_SUPPORT_ICO 0
    #define CXIMAGE_SUPPORT_TIF 1
    #define CXIMAGE_SUPPORT_TGA 0
    #define CXIMAGE_SUPPORT_PCX 0
    #define CXIMAGE_SUPPORT_WBMP 0
    #define CXIMAGE_SUPPORT_WMF 0
    #define CXIMAGE_SUPPORT_JP2 0
    #define CXIMAGE_SUPPORT_JPC 0
    #define CXIMAGE_SUPPORT_PGX 0
    #define CXIMAGE_SUPPORT_PNM 0
    #define CXIMAGE_SUPPORT_RAS 0
    #define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm
    #define CXIMAGE_SUPPORT_MNG 0
    #define CXIMAGE_SUPPORT_SKA 0

    #define CXIMAGE_SUPPORT_RAW 0 

    把自己不需要的功能修改为0,需要的为1. 

    然后开始编译cximage,编译前注意Debug版本就都要用Debug的库,Realese版本就都用Realese库,首先报错

     D:\cximage600_full_cp\CxImage\ximadsp.cpp|3507|error: 'max' was not declared in this scope|

    D:\cximage600_full_cp\CxImage\ximadsp.cpp|3507|error: 'min' was not declared in this scope| 

    查看了max,min其实有定义的,但是找不到奇怪,在ximadsp.cpp上加上using namespace std; 用std里面的先代替吧,

    继续编译,又提示

    D:\cximage600_full_cp\CxImage\ximaexif.cpp|752|error: 'isprint' was not declared in this scope| 

    没找到isprint,在linux下man一下,发现在ctype里,加上#include <ctype.h> ,继续,仍然报错

    D:\cximage600_full_cp\CxImage\ximawnd.cpp|1222|error: '_tcsclen' was not declared in this scope| 

    把_tcsclen替换为_tcslen函数,再编译,终于成功了

    ar.exe: creating D:\cximage600_full_cp\CxImage\Debug\libcximage.a 

    为了测试是否真的成功了,自己写个测试程序测试

     1 #include <iostream>
     2 #include "../ximage.h"
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     CxImage img;
     9     img.Load("./old.jpg",CXIMAGE_FORMAT_JPG);
    10     if(img.IsValid())
    11     {
    12         img.Save("./new.png",CXIMAGE_FORMAT_PNG);
    13     }
    14 
    15     return 0;

    16 }

    设置好工程的链接目录和链接库,先在Search directories的Linker里设置libs的路径,我这里为http://www.cnblogs.com/libs,然后在Linker Settings的Other linker options:中加入

    -lcximage
    -lTiff
    -lpng
    -lJpeg

    -lzlib

    编译报错

    ..\..\libs\libcximage.a(ximasel.o):ximasel.cpp|| undefined reference to `CreateRectRgn@16'|
    ..\..\libs\libcximage.a(ximasel.o):ximasel.cpp|| undefined reference to `CombineRgn@16'|
    ..\..\libs\libcximage.a(ximasel.o):ximasel.cpp|| undefined reference to `DeleteObject@4'|
    ..\..\libs\libcximage.a(ximasel.o):ximasel.cpp|| undefined reference to `CreateRectRgn@16'|
    ..\..\libs\libcximage.a(ximasel.o):ximasel.cpp|| undefined reference to `CombineRgn@16'|
    ..\..\libs\libcximage.a(ximasel.o):ximasel.cpp|| undefined reference to `DeleteObject@4'|
    ||=== Build finished: 6 errors, 0 warnings ===|

     g了一下是gdi32里的函数,在链接库里面再加上-lgdi32,再编译成功,经测试,测试程序已经可以实行图像格式转换了

    最后是打包发布,让其他程序可以调用他 

    把libs目录拷出来,还有以下头文件

     xfile.h ximacfg.h ximadef.h ximage.h xiofile.h xmemfile.h

    调用的时候只要include ximage.h就可以了

    提供一个我编译好的库cximage_mingw

    最后吐槽一下,个人觉得cximage并不是很好用,代码的移植性并不算太好,不像是个跨平台项目. 继续寻找其他的开源图像库

  • 相关阅读:
    Redis命令总结
    jvisualvm远程监控Tomcat
    CentOS6安装glibc-2.14,错误安装libc.so.6丢失急救办法
    vsan分布式存储数据恢复全过程
    linux文件系统损坏修复方法,亲测可用
    案例讲解服务器硬盘离线数据恢复方法-数据恢复
    服务器数据丢失恢复过程
    数据恢复工程师讲述Linux服务器数据恢复过程
    了解这一点轻松解决Oracle数据库系统报错问题
    浅析RAID0/1安全差别及处理数据安全的应对方式
  • 原文地址:https://www.cnblogs.com/Red_angelX/p/2663296.html
Copyright © 2020-2023  润新知