在程序中使用GDI+的步骤

本文详细介绍了使用 GDI+ 进行绘图的五个必要步骤,包括引入头文件、使用命名空间、链接库文件、初始化及释放系统资源,并概述了 Graphics 类的多种构造方法和静态方法。

使用之前,你必须做下面5个步骤:

(1)创建一个工程,引入GDI+头文件

          #include <GdiPlus.h>


(2)使用GDI+命名空间
          using namespace Gdiplus;

          要不然会出现很多未定义符号的错误


(3)引入Gdiplus.lib库
        #pragma comment(lib,"Gdiplus.lib")

        要不然编译时会出现找不到实现的错误


(4)在使用前初始化GDI+系统资源

          一般是在app类的初始化方法中

         ULONG_PTR gdiplusToken;//得保证这个变量在释放GDI+资源时也能访问得到,一般设为全局变量

         GdiplusStartupInput gdiplusStartupInput;

GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,NULL);


(5)使用完毕后,释放GDI+系统资源

         一般是在app类的析构函数中或者ExitInstance函数中或者Instance函数末尾中调用

        GdiplusShutdown(gdiplusToken);




GDI+的使用:

    通常,你需要创建一个Graphics对象来使用GDI+提供的各种绘图函数。

构造函数:

The Graphics class has these constructors.

ConstructorDescription
Graphics::Graphics(HDC)

Creates a Graphics::Graphics object that is associated with a specified device context.

Graphics::Graphics(HDC,HANDLE)

Creates a Graphics::Graphics object that is associated with a specified device context and a specified device.

Graphics::Graphics(HWND,BOOL)

Creates a Graphics::Graphics object that is associated with a specified window.

Graphics::Graphics(Image*)

Creates a Graphics::Graphics object that is associated with an Image object. 


除了上面的构造函数外,还有Graphics类提供了下面几个静态函数。它们更好用。

Graphics::FromHDC(HDC)

The Graphics::FromHDC method creates a Graphics object that is associated with a specified device context.

Graphics::FromHDC(HDD,HANDLE)

The Graphics::FromHDC method creates a Graphics object that is associated with a specified device context and a specified device.

Graphics::FromHWND

The Graphics::FromHWND method creates a Graphics object that is associated with a specified window.

Graphics::FromImage

The Graphics::FromImage method creates a Graphics object that is associated with a specifiedImage object. 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值