C# 图形化编程 System.Drawing

最近做了一个类似形地图标注的一个小项目,总结一下图形化编程的一点心得。

首先来看看几个重要的画图对象:

System.Drawing.Graphics   //画布
System.Drawing.Drawing2D.GraphicsPath   //画图路径,也就是在图上显示的线
System.Drawing.Drawing2D.Matrix  //图像缩放对象


我们再来看看几个重要方法:

//g为Graphics对象 path为GraphicsPath对象
path.AddLine(Point1, Point2);  //在两点间添加一条直线
path.AddArc(x,y,width,height,startAngle,sweepAngle); //添加弧线
path.AddPie(x,y,width,height,startAngle,sweepAngle); //添加扇形 
g.DrawPath(new Pen(Color.Gray, 1), path); //将路径画到画布
g.FillEllipse(brush,x,y,width,height); //在画布上画一个椭圆
g.DrawLine(pen,point1,point2); //在画布上画一条直线
path.Transform(matrix);  //将图像按比例缩放
g.TranslateTransform(x, y, MatrixOrder.Prepend); //平移画布


This Wrox Blox teaches you how to add graphics to C# 2008 applications, explaining fundamental graphics techniques such as: drawing shapes with different colors and line styles; filling areas with colors, gradients, and patterns; drawing text that is properly aligned, sized, and clipped exactly where you want it; manipulating images and saving results in bitmap, JPEG, and other types of files. Also covered are instructions for how to greatly increase your graphics capabilities using transformations. Transformations allow you to move, stretch, or rotate graphics. They also let you work in coordinate systems that make sense for your application. You will also learn how to use all of these techniques in printouts. The author describes the sequence of events that produce a printout and shows how to generate and preview printouts. The final sections describe two powerful new graphic tools that were introduced with .NET Framework 3.0: WPF graphics and FlowDocuments. WPF applications can use XAML graphic commands to declaratively draw and fill the same kinds of shapes that a program can draw by using graphics objects. Finally, a discussion on the FlowDocument object shows you how to define items that should be flowed across multiple pages as space permits. This lets you display text, graphics, controls, and other items that automatically flow across page breaks. FlowDocument viewers make displaying these documents easy for you, and simplifies the user's reading of the documents. This Wrox Blox also contains 35 example programs written in C# 2008, although most of the code works in previous versions of C# as well. The most notable exceptions are WPF graphics and FlowDocuments, both of which require WPF provided in .NET Framework 3.0 and later.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值