用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並不是很好用,代碼的移植性並不算太好,不像是個跨平臺項目. 繼續尋找其他的開源圖像庫

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章