Using CxImage in your projects The CxImgLib.dsw workspace shows the libraries required to build an application (demo.exe) including almost all the features and the formats available in CxImage. You must compile all the libraries before you can link the final application. In the same workspace you'll find the projects to build different libraries and applications:CxImage : cximage.lib - static library CxImageCrtDll : cximagecrt.dll - DLL not using mfc CxImageMfcDll : cximage.dll - DLL using mfc Demo : demo.exe - program linked with cximage.lib and the C libraries DemoDll : demodll.exe - program linked with cximagecrt.dll j2k,jasper,jbig,jpeg,png,tiff,zlib : static C libraries Building the projects will need some minutes to complete (the intermediate files occupy 60MB!). When everything is done, select the demo project and launch the application. CxImgLib.dsw To use CxImage in your project, you must edit these settings: Project Settings |- C/C++ | |- Code Generation | | |- Use run-time library : Multithreaded DLL (must be the same for | | | all the linked libraries) | | |- Struct member alignment : must be the same for all the linked | | | libraries | |- Precompiled headers : not using precompiled headers | |- Preprocessor | |- Additional Include Directories: ..\cximage |- Link |- General |- Object/library modules: ../png/Debug/png.lib ../jpeg/Debug/jpeg.lib ../zlib/Debug/zlib.lib ../tiff/Debug/tiff.lib ../jasper/Debug/jasper.lib ../cximage/Debug/cximage.lib ...
我按照这样做了,可是依旧没有像demo那样,把那些类加进自己的工程。而且在编译的时候,出现了,defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library,这样的waring.帮人帮到底,帮我说清楚一点吧,我第一次接触用到这种库。谢谢了:)同时,还让我觉得迷惑的还有CxImgLib,这个里面怎么有那么多的工程。我第一次看到,能给我解释解释吗?
Cximage 使用了别人的图像编码的库 比如jpeg2000 jpeg 这些都是使用现成的库
刚才又改了一下,我对我的工程作了这样的修改。除了设置以外,Doc类里面添加了成员变量CxImage* m_image,并且添加了OnOpenDocument函数,用来打开。 // TODO: Add your specialized creation code here CString filename(lpszPathName); CString ext(FindExtension(filename)); ext.MakeLower(); if (ext == "") return FALSE; if (ext == "bmp") type = CXIMAGE_FORMAT_BMP; #if CXIMAGE_SUPPORT_JPG else if (ext=="jpg"||ext=="jpeg") type = CXIMAGE_FORMAT_JPG; #endif #if CXIMAGE_SUPPORT_GIF else if (ext == "gif") type = CXIMAGE_FORMAT_GIF; #endif #if CXIMAGE_SUPPORT_PNG else if (ext == "png") type = CXIMAGE_FORMAT_PNG; #endif #if CXIMAGE_SUPPORT_MNG else if (ext=="mng"||ext=="jng") type = CXIMAGE_FORMAT_MNG; #endif #if CXIMAGE_SUPPORT_ICO else if (ext == "ico") type = CXIMAGE_FORMAT_ICO; #endif #if CXIMAGE_SUPPORT_TIF else if (ext=="tiff"||ext=="tif") type = CXIMAGE_FORMAT_TIF; #endif #if CXIMAGE_SUPPORT_TGA else if (ext=="tga") type = CXIMAGE_FORMAT_TGA; #endif #if CXIMAGE_SUPPORT_PCX else if (ext=="pcx") type = CXIMAGE_FORMAT_PCX; #endif #if CXIMAGE_SUPPORT_WBMP else if (ext=="wbmp") type = CXIMAGE_FORMAT_WBMP; #endif #if CXIMAGE_SUPPORT_WMF else if (ext=="wmf"||ext=="emf") type = CXIMAGE_FORMAT_WMF; #endif #if CXIMAGE_SUPPORT_J2K else if (ext=="j2k"||ext=="jp2") type = CXIMAGE_FORMAT_J2K; #endif #if CXIMAGE_SUPPORT_JBG else if (ext=="jbg") type = CXIMAGE_FORMAT_JBG; #endif else return FALSE; m_image = new CxImage(filename, type); if (!m_image->IsValid()){ AfxMessageBox(m_image->GetLastError()); delete m_image; m_image = NULL; return FALSE; } return TRUE;
最后,还有一个函数用来返回m_image,用作显示。在View的OnDraw里面添加了 CxImage* ima = pDoc->GetImage(); if (ima) { ima->Draw(pDC->GetSafeHdc(), CRect(0,0,(int)(ima->GetWidth()),(int)(ima->GetHeight()))); }然而,这样,最后编译可以通过,并且warning也没有了。可是执行起来,却出现错误。
先编译,设置vc的头、源文件路径
然后在使用的地方加上 #include "ximage.h"
The CxImgLib.dsw workspace shows the libraries required to build an application (demo.exe) including almost all the features and the formats available in CxImage. You must compile all the libraries before you can link the final application.
In the same workspace you'll find the projects to build different libraries and applications:CxImage : cximage.lib - static library
CxImageCrtDll : cximagecrt.dll - DLL not using mfc
CxImageMfcDll : cximage.dll - DLL using mfc
Demo : demo.exe - program linked with cximage.lib and the C libraries
DemoDll : demodll.exe - program linked with cximagecrt.dll
j2k,jasper,jbig,jpeg,png,tiff,zlib : static C libraries
Building the projects will need some minutes to complete (the intermediate files occupy 60MB!). When everything is done, select the demo project and launch the application.
CxImgLib.dsw
To use CxImage in your project, you must edit these settings: Project Settings
|- C/C++
| |- Code Generation
| | |- Use run-time library : Multithreaded DLL (must be the same for
| | | all the linked libraries)
| | |- Struct member alignment : must be the same for all the linked
| | | libraries
| |- Precompiled headers : not using precompiled headers
| |- Preprocessor
| |- Additional Include Directories: ..\cximage
|- Link
|- General
|- Object/library modules: ../png/Debug/png.lib
../jpeg/Debug/jpeg.lib
../zlib/Debug/zlib.lib
../tiff/Debug/tiff.lib
../jasper/Debug/jasper.lib
../cximage/Debug/cximage.lib ...
// TODO: Add your specialized creation code here
CString filename(lpszPathName);
CString ext(FindExtension(filename));
ext.MakeLower();
if (ext == "") return FALSE;
if (ext == "bmp") type = CXIMAGE_FORMAT_BMP;
#if CXIMAGE_SUPPORT_JPG
else if (ext=="jpg"||ext=="jpeg") type = CXIMAGE_FORMAT_JPG;
#endif
#if CXIMAGE_SUPPORT_GIF
else if (ext == "gif") type = CXIMAGE_FORMAT_GIF;
#endif
#if CXIMAGE_SUPPORT_PNG
else if (ext == "png") type = CXIMAGE_FORMAT_PNG;
#endif
#if CXIMAGE_SUPPORT_MNG
else if (ext=="mng"||ext=="jng") type = CXIMAGE_FORMAT_MNG;
#endif
#if CXIMAGE_SUPPORT_ICO
else if (ext == "ico") type = CXIMAGE_FORMAT_ICO;
#endif
#if CXIMAGE_SUPPORT_TIF
else if (ext=="tiff"||ext=="tif") type = CXIMAGE_FORMAT_TIF;
#endif
#if CXIMAGE_SUPPORT_TGA
else if (ext=="tga") type = CXIMAGE_FORMAT_TGA;
#endif
#if CXIMAGE_SUPPORT_PCX
else if (ext=="pcx") type = CXIMAGE_FORMAT_PCX;
#endif
#if CXIMAGE_SUPPORT_WBMP
else if (ext=="wbmp") type = CXIMAGE_FORMAT_WBMP;
#endif
#if CXIMAGE_SUPPORT_WMF
else if (ext=="wmf"||ext=="emf") type = CXIMAGE_FORMAT_WMF;
#endif
#if CXIMAGE_SUPPORT_J2K
else if (ext=="j2k"||ext=="jp2") type = CXIMAGE_FORMAT_J2K;
#endif
#if CXIMAGE_SUPPORT_JBG
else if (ext=="jbg") type = CXIMAGE_FORMAT_JBG;
#endif
else return FALSE; m_image = new CxImage(filename, type); if (!m_image->IsValid()){
AfxMessageBox(m_image->GetLastError());
delete m_image;
m_image = NULL;
return FALSE;
}
return TRUE;
最后,还有一个函数用来返回m_image,用作显示。在View的OnDraw里面添加了
CxImage* ima = pDoc->GetImage();
if (ima) {
ima->Draw(pDC->GetSafeHdc(),
CRect(0,0,(int)(ima->GetWidth()),(int)(ima->GetHeight())));
}然而,这样,最后编译可以通过,并且warning也没有了。可是执行起来,却出现错误。