//创建一个图片对象
Bitmap bt = new Bitmap(120, 40);
//创建画笔对象
Graphics gp = Graphics.FromImage(bt);
Random randm = new Random();//创建随机数对象
string str = "";//声明一个字符串变量
for (int i = 0; i < 5; i++)//将生成的随机数赋值给字符串
{
int rNum = randm.Next(0, 10);
str += rNum;
}
InstalledFontCollection fonts = new InstalledFontCollection();//创建安装系统字体类型对象
FontFamily[] fs = fonts.Families; //创建FontFamily对象,接受字体类型数组
//for (int i = 0; i < fs.Length;i++ )
//{
// comboBox1.Items.Add(fs[i]);
//}
Color[] colors = {Color.Red,Color.RosyBrown,Color.SeaGreen,Color.PaleTurquoise,Color.Olive };//创建Color类型
for (int i = 0; i < 5; i++)
{
//要求画的这五个随机数,间隔为20
Point p = new Point(i * 30, 0);
gp.DrawString(str[i].ToString(), new Font(fs[i], 20, FontStyle.Bold), new SolidBrush(colors[i]), p);
}
//画线
for (int i = 0; i < 5; i++)
{
Point p1 = new Point(randm.Next(0, bt.Width), randm.Next(0, bt.Height));
Point p2 = new Point(randm.Next(0, bt.Width), randm.Next(0, bt.Height));
gp.DrawLine(new Pen(Color.Pink),p1,p2);
}
//画像素
for (int i = 0; i < 500; i++)
{
bt.SetPixel(randm.Next(0, bt.Width), randm.Next(0, bt.Height), Color.Black);
}
//将创建的图片镶嵌到pictureBox上
pictureBox1.Image = bt; |
|