上一篇 | 下一篇

使用GDI在内存中转换图片类型

发布: 2008-6-26 14:24 | 作者: admin | 来源: | 查看: 32次

微软新推出的GDI+功能强大,本文仅对图片转换加以讨论,不足之处请大家指出.

图片类型的转换支持:bmp、dib、png、gif、jpeg/jpg、tiff、emf等

以下是详细步骤。

首先在StdAfx.h中静态调用diplus.lib,即由编译系统完成对DLL的加载,应用程序结束时卸载DLL的编码。如下:

#ifndef ULONG_PTR

#define ULONG_PTR unsigned long*

#include "GdiPlus.h"

using namespace Gdiplus;

#pragma comment(lib, "gdiplus.lib")

#endif

在类的头文件中定义,以下成员变量,用来初始化GDI+的使用和结束使用。

GdiplusStartupInput m_gdiplusStartupInput;

ULONG_PTR m_gdiplusToken;

然后在OnCreate()函数中加入初始化GDI+的函数:

GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);

在OnDestroy()函数中加入结束GDI+使用的函数:

GdiplusShutdown(m_gdiplusToken);

接着定义转换函数

BOOL MBmpToMImage(CMemFile& cbfBmp, CMemFile& cbfImage, CString strType)

其中:

CMemFile& cbfBmp表示原位图文件;

字号: | 推荐给好友

51/512345>

评分:0

我来说两句

网络推荐