CXImage的基本使用

本文由 @lonelyrains 出品,转载请注明出处。 
文章链接: http://blog.csdn.net/lonelyrains/article/details/8772718


       首先下载可用版本CXImage6.0.0,链接地址为 http://download.csdn.net/detail/lonelyrains/5233564。

       编译:打开根目录下的CxImgLib.dsw工程文件,默认的编译是采用unicode-release方式编译的。为了在一般的vc6.0工程中使用,请改用debug/release版本,不包含unicode前缀。batch build编译成功后会生成一些lib文件、dll文件和demo.exe。

       新建MFC测试工程,在lib文件夹中包含CxImgLib的头文件、lib文件

在工程目录下添加dll文件:cximage.dll cximagecrtd.dll

修改stdafx.h文件,

// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//

#if !defined(AFX_STDAFX_H__0816B0BC_058B_410B_AB0D_3DB7188938DE__INCLUDED_)
#define AFX_STDAFX_H__0816B0BC_058B_410B_AB0D_3DB7188938DE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>			// MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

//添加CxImage到你的程序中(目录为你上面添加位置,我把它们放在了lib文件夹中了)
#include "lib/ximage.h"
#pragma comment(lib,"lib/cximagecrtd.lib") //静态链接库时使用
#pragma comment(lib,"lib/cximage.lib")
#pragma comment(lib,"lib/Jpeg.lib")
#pragma comment(lib,"lib/consoleu.lib")
#pragma comment(lib,"lib/png.lib")
#pragma comment(lib,"lib/zlib.lib")
#pragma comment(lib,"lib/tiff.lib")
#pragma comment(lib,"lib/jasper.lib")
//#pragma comment(lib,"lib/j2k.lib")
#pragma comment(lib,"lib/jbig.lib")
#pragma comment(lib,"lib/libdcr.lib")
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__0816B0BC_058B_410B_AB0D_3DB7188938DE__INCLUDED_)
为测试的MFC工程添加一个按钮事件,添加代码

void CCxImageTestDlg::OnBtnSave() 
{
	// TODO: Add your control notification handler code here
	//创建对象
	CxImage *newImage = new CxImage();
	newImage->Load("test.png",CXIMAGE_FORMAT_PNG);

	//存储为文件,我发现的可以使用的有6个格式有三个格式未使用成功(gif,wbmg,wmf)....够用了吧?
	newImage->Save("image.bmp",CXIMAGE_FORMAT_BMP); //注意不是CXIMAGE_SUPPORT_BMP
	newImage->Save("image.tga",CXIMAGE_FORMAT_TGA);
	newImage->Save("image.pcx",CXIMAGE_FORMAT_PCX);
	newImage->Save("image.jpg",CXIMAGE_FORMAT_JPG);
	newImage->Save("image.png",CXIMAGE_FORMAT_PNG);
	newImage->Save("image.tiff",CXIMAGE_FORMAT_TIF);

	newImage->Save("image.gif",CXIMAGE_FORMAT_GIF); //不成功,只能读取第一贞图片?
	newImage->Save("image.wbmp",CXIMAGE_FORMAT_WBMP); //不成功
	newImage->Save("image.wmf",CXIMAGE_FORMAT_WMF); //不成功

	newImage->Save("image.mng",CXIMAGE_FORMAT_MNG); //默认-未打开此项功能
	//newImage->Save("image.jbig",CXIMAGE_FORMAT_JBG); //默认-未打开此项功能
	/*
	 * CxImage配置文件ximacfg.h
	 * #define CXIMAGE_SUPPORT_BMP 1 //可用状态(即不可取得和转换成这种格式)
	 * #define CXIMAGE_SUPPORT_MNG 0 //不可用状态
	*/
}

修改编译选项:在project->setting->link->input->ignore lib中添上msvcrt.lib,避免与之冲突

编译后即可将test.png转成各种各样的image+后缀格式的文件


参考链接:http://wupei.j2megame.org/archives/31

你可能感兴趣的:(CXImage的基本使用)