用C#的Graphics绘图

本文介绍了一个使用 C# 的 Graphics 类绘制随机封闭曲线的例子。程序首先生成8个随机坐标点,然后利用 DrawClosedCurve 方法绘制出一条平滑的封闭曲线。

用C#的Graphics绘图

这个程序先随机生成8个点,再用Graphics的DrawCloseCurves方法画出封闭曲线。
using System;
using System.Drawing;
using System.Drawing.Text;
class haidao{
static void Main(){
Bitmap bmp=new Bitmap(800,800);
Graphics g=Graphics.FromImage(bmp);
FontFamily fontfml=new FontFamily(GenericFontFamilies.Serif);
Font font=new Font(fontfml,20);
SolidBrush brush=new SolidBrush(Color.Red);
g.DrawString("Haidao using C# drawing this.",font,brush,50,10);
Random rnd=new Random();
Point[] haidao=new Point[8];
haidao[0]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
haidao[1]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
haidao[2]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
haidao[3]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
haidao[4]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
haidao[5]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
haidao[6]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
haidao[7]=new Point(rnd.Next(600)+100,rnd.Next(600)+100);
Pen curvepen=new Pen(Color.Red);
curvepen.Width=3;
g.DrawClosedCurve(curvepen,haidao);
bmp.Save("haidao.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值