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
#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
爲了測試是否真的成功了,自己寫個測試程序測試
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:中加入
-lTiff
-lpng
-lJpeg
-lzlib
編譯報錯
g了一下是gdi32裏的函數,在鏈接庫裏面再加上-lgdi32,再編譯成功,經測試,測試程序已經可以實行圖像格式轉換了
最後是打包發佈,讓其他程序可以調用他
把libs目錄拷出來,還有以下頭文件
xfile.h ximacfg.h ximadef.h ximage.h xiofile.h xmemfile.h
調用的時候只要include ximage.h就可以了
提供一個我編譯好的庫cximage_mingw
最後吐槽一下,個人覺得cximage並不是很好用,代碼的移植性並不算太好,不像是個跨平臺項目. 繼續尋找其他的開源圖像庫