很长一段时间没有更新技术博客了,最近在用C#开发Kinect的程序。所以跟大家分享一下自己一些方面学习和认知。
编写图形程序时需要使用GDI(Graphics Device Interface,图形设备接口),从程序设计的角度看,GDI包括两部分:一部分是GDI对象,另一部分是GDI函数。GDI对象定义了GDI函数使用的工具和环境变量,而GDI函数使用GDI对象绘制各种图形,在C#中,进行图形程序编写时用到的是GDI+(Graphics Device Interface Plus图形设备接口)版本,GDI+是GDI的进一步扩展,它使我们编程更加方便。
C#中的GDI+就相当于java中的Swing控件,是编写图形界面必不可缺的一个接口。GDI+绘图最大的方便得益于C#的可视化编程,所有的控件只需要自己Drag,然后Place,最后Cilck添加监听方法。真的是too young too simple。
绘图的时候要用到Graphics类,所以首先介绍一下Graphics画布
我们首先要创建一个Graphics类实例,这个实例相当于建立了一块画布,有了画布才可以用各种画图方法进行绘图。这个过程其实与java中Swing控件获取画布形式上差不多。
绘图程序的设计过程一般分为两个步骤:(一)创建Graphics对