VC6.0中gdiPlus的使用以及一个小例子
2009-05-09 13:19
218 查看
1.GDIPlus需要下载sdk开发包
2.在tool,option,direction,include files下设置头文件路径.../MICROSOFT SDK/INCLUDE,在tool,option,direction,libaray files下设置lib路径.../MICROSOFT SDK/SDK8/LIB,在project, setting, link, object/modules libaray里面输入gdiplus.lib.
注意,路径一定要放在最上层,还有,一定要是绝对路径,上面的...需要自己补充完整
3.新建一个单文档工程XXX,给XXXApp类添加成员变量
protected:
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_gdiplusToken;
在XXXApp::InitInstance()里面添加:GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);
重载XXXApp::ExitInstance(),在里面添加:GdiplusShutdown(m_gdiplusToken);
注意,以上修改过的文件前面要加上以下语句:
#include <GdiPlus.h>
using namespace Gdiplus;
上面的事情做完,你就可以在程序中使用gdiplus了,以下是一个把bmp转换成jpg的小例子:
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
void BMP2JPG(CString strBMPFile,CString strJPGFile)
{
CLSID encoderClsid;
WCHAR strGuid[39];
if(GetEncoderClsid(L"image/jpeg", &encoderClsid) >= 0)
StringFromGUID2(encoderClsid, strGuid, 39);
Image image(strBMPFile.AllocSysString());
image.Save(strJPGFile.AllocSysString(),&encoderClsid,NULL);
}
当然,上面的例子所在文件前面也必须加上
#include <GdiPlus.h>
using namespace Gdiplus;
2.在tool,option,direction,include files下设置头文件路径.../MICROSOFT SDK/INCLUDE,在tool,option,direction,libaray files下设置lib路径.../MICROSOFT SDK/SDK8/LIB,在project, setting, link, object/modules libaray里面输入gdiplus.lib.
注意,路径一定要放在最上层,还有,一定要是绝对路径,上面的...需要自己补充完整
3.新建一个单文档工程XXX,给XXXApp类添加成员变量
protected:
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_gdiplusToken;
在XXXApp::InitInstance()里面添加:GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);
重载XXXApp::ExitInstance(),在里面添加:GdiplusShutdown(m_gdiplusToken);
注意,以上修改过的文件前面要加上以下语句:
#include <GdiPlus.h>
using namespace Gdiplus;
上面的事情做完,你就可以在程序中使用gdiplus了,以下是一个把bmp转换成jpg的小例子:
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
void BMP2JPG(CString strBMPFile,CString strJPGFile)
{
CLSID encoderClsid;
WCHAR strGuid[39];
if(GetEncoderClsid(L"image/jpeg", &encoderClsid) >= 0)
StringFromGUID2(encoderClsid, strGuid, 39);
Image image(strBMPFile.AllocSysString());
image.Save(strJPGFile.AllocSysString(),&encoderClsid,NULL);
}
当然,上面的例子所在文件前面也必须加上
#include <GdiPlus.h>
using namespace Gdiplus;
相关文章推荐
- 转VC6.0中gdiPlus的使用以及一个bmp转jpg的小例子[bobob原创]
- VC6.0中gdiPlus的使用以及一个bmp转jpg的小例子
- VC6.0中gdiPlus的使用以及一个小例子
- spring笔记--使用springAPI以及自定义类 实现AOP的一个例子
- Redis的安装、使用以及php中扩展redis并实现php操作redis的一个例子
- spring笔记--使用springAPI以及自定义类 实现AOP的一个例子
- 一个例子包含mvp、rxjava以及retrofit2的使用
- 事件代理总结: 已经有一些使用主流类库的事件代理示例出现了,比如说jQuery、Prototype以及Yahoo! UI。你也可以找到那些不用任何类库的例子,比如说Usable Type blog上的这一个。一旦需要的话,事件代理将是你工具箱里的一件得心应手的工具,而且它很容易实现。
- 一个mat和iplimage以及使用cvInRangeS批量修改矩阵值例子
- FMDB的使用详解以及一个简单的小例子
- 关于二级指针的使用测试小例子,仅供测试--参数传递的时候用指针最好,因为压栈的时候指针,只是压入一个地址的值,最多4个字节(32位机上),提供的3个测试例子,基于VC6.0的环境。
- 使用PHP的curl扩展实现跨域post请求,以及file_get_contents()百度短网址例子
- 一个case查询语句的使用例子
- 使用dll以及调用dll例子
- [转载]高效使用matlab之四:一个加速matlab程序的例子
- 昨天写的使用<cctype>的一个例子
- 快速使用 SQLite 开源数据库 一个Asp.Net 的小例子
- 11.4 一个现实中使用sizer的例子 [wxPython in Action]
- 使用js中常用的鼠标事件实现一个拖拽的例子
- Webpack入门——使用Webpack打包Angular项目的一个例子