CxImage的編譯及簡單使用舉例
1、 從http://sourceforge.net/projects/cximage/下載最新的CxImage 702源碼;
2、 解壓縮後,以管理員身份打開CxImageFull_vc10.sln工程,在編譯之前先將每個工程屬性的Character Set由原先的Use Unicode Character Set改為Use Multi-ByteCharacter Set,首先編譯jasper、jbig、jpeg、libdcr、libpsd、mng、png、tiff、zlib這9個庫,然後編譯cximage,cximagecrtdll,在接著編譯cximagemfcdll,在編譯cximagemfcdll之前,先修改其屬性,linker->input->Additional Dependencies,將$(OutDir)png.lib等改為../../Debug/png.lib(../../Release/png.lib),最後編譯demo、demodll;全部編譯完後即可生成相應的靜態庫和動態庫;
3、 目前CxImage支持的圖像格式包括:bmp、gif、jpg、png、ico、tif、tga、pcx、wbmp、wmf、jp2、jpc、pgx、pnm、ras、jbg、mng、ska、raw和psd;
4、 CxImage中所包含的圖像操作可通過打開index.htm來查看;
5、新建一個控制臺工程testCxImage,將Character Set設為Use Multi-Byte Character Set,各個文件的內容為:
stdafx.h:
[cpp] view plain copy
- #pragma once
- #include "targetver.h"
- #include <stdio.h>
- #include "../../cximage702_full/CxImage/ximage.h"
stdafx.cpp:
[cpp] view plain copy
- #include "stdafx.h"
- // TODO: reference any additional headers you need in STDAFX.H
- // and not in this file
- #ifdef _DEBUG
- #pragma comment(lib, "../../cximage702_full/Debug/cximage.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/jasper.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/jbig.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/jpeg.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/libdcr.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/libpsd.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/mng.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/png.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/tiff.lib")
- #pragma comment(lib, "../../cximage702_full/Debug/zlib.lib")
- #else
- #pragma comment(lib, "../../cximage702_full/Release/cximage.lib")
- #pragma comment(lib, "../../cximage702_full/Release/jasper.lib")
- #pragma comment(lib, "../../cximage702_full/Release/jbig.lib")
- #pragma comment(lib, "../../cximage702_full/Release/jpeg.lib")
- #pragma comment(lib, "../../cximage702_full/Release/libdcr.lib")
- #pragma comment(lib, "../../cximage702_full/Release/libpsd.lib")
- #pragma comment(lib, "../../cximage702_full/Release/mng.lib")
- #pragma comment(lib, "../../cximage702_full/Release/png.lib")
- #pragma comment(lib, "../../cximage702_full/Release/tiff.lib")
- #pragma comment(lib, "../../cximage702_full/Release/zlib.lib")
- #endif
testCxImage.cpp:
[cpp] view plain copy
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- int main(int argc, char* argv[])
- {
- CxImage image;
- string imageName = "1.jpg";
- string imageSave = "2.tif";
- image.Load(imageName.c_str(), CXIMAGE_FORMAT_JPG);
- cout<<image.GetBpp()<<endl;
- if (image.IsValid()) {
- image.GrayScale();
- image.Save(imageSave.c_str(), CXIMAGE_FORMAT_TIF);
- cout<<"success"<<endl;
- }
- cout<<"ok"<<endl;
- return 0;
- }
GitHub:https://github.com/fengbingchun/CxImage_Test
CxImage的編譯及簡單使用舉例