1.生成图片方法
public void GetImg(){
Random rd = new Random();
int num = rd.Next(1, 7);//1-7随机数
int initWidth = 256;
int initHeight = 256;
// \uff21-\uff3a 大写字母A-Z
// \uff41-\uff5a 小写字母a-z
// \u4e00-\u9f5a 汉字
// 48-57 0-9数字
for (var c = '\uff41'; c <= '\uff5a'; c++)
{
Bitmap image = new Bitmap(initWidth, initHeight);//初始化大小
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;//设置图片质量
num = (int)c;
switch (num % 8)//设置图片不同背景色
{
case 1:
g.Clear(Color.FromArgb(255, 139, 139));
break;
case 2:
g.Clear(Color.FromArgb(97, 191, 173));
break;
case 3:
g.Clear(Color.FromArgb(22, 124, 127));
break;
case 4:
g.Clear(Color.FromArgb(50, 182, 122));
break;
case 5:
g.Clear(Color.FromArgb(191, 181, 215));
break;
case 6:
g.Clear(Color.FromArgb(240, 207, 97));
break;
case 7:
g.Clear(Color.FromArgb(5, 90, 91));
break;
default:
g.Clear(Color.FromArgb(5, 90, 91));
break;
}
Font f = new Font("Arial ", 88);//, System.Drawing.FontStyle.Bold);//设置字体样式,大小
Brush b = new SolidBrush(Color.White);
Brush r = new SolidBrush(Color.FromArgb(166, 8, 8));
g.DrawString(c.ToString(), f, b, 45, 60);//设置位置
image.Save(Application.StartupPath + "\\img\\" + (num).ToString() + ".jpg", ImageFormat.Jpeg);//自己创建一个文件夹,放入生成的图片(根目录下)
}
}