使用GDI+显示PNG

用GDI+是最简单的办法。

一、GDI+加到VC工程的具体做法如下:

1、下载GDI+ 软件包。
2、在头文件StdAfx.h 内增加下述语句:
    typedef unsigned __int32 ULONG_PTR;
    #include <afxtempl.h>
    #include "gdiplus.h"
    #pragma comment(lib, "gdiplus.lib")
    using namespace Gdiplus;
3、将GDI+的所有头文件及库文件及DLL考到当前目录。
4、初始化GDI+的环境:(增加两个函数在APP.CPP)
   bool CXXXXApp::InitGdiplus()  //CXXXXApp:改成你定义的类。
  {
   GdiplusStartupInput gdiplusStartupInput;
   Status status = GdiplusStartup(&m_gdiplusToken,
                                  &gdiplusStartupInput,
                                  NULL);
   return (Ok == status);
  }

  void CXXXXApp::TermGdiplus()
  {
   GdiplusShutdown(m_gdiplusToken);
  }
5、在APP.H 增加对函数的定义:
bool InitGdiplus();
void TermGdiplus();
ULONG_PTR m_gdiplusToken;
6、在APP的InitInstance() 增加如下的初始化语句:
    if(false == InitGdiplus())
   {
      ::MessageBox(NULL, _T("Initialize GDI+ library failed"),
                   _T("Error"), MB_OK|MB_ICONERROR);
      return FALSE;
   } 
7、在退出程序的地方调用TermGdiplus();函数,关闭GDI+环境。

二、完成上述内容后,在需要加PNG图片的地方直接调用GDI+内的相关函数即可。

转载于:https://www.cnblogs.com/zzili/archive/2012/12/06/6663334.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值