产生随机图片,并返回图片内的文字
2005-10-10 16:56
316 查看
public string R_random(System.Web.UI.WebControls.Image img,string path)
string tmp;//文字
Random rnd=new Random();
tmp=rnd.Next().ToString().Substring(0,4);
Graphics g=null;
Bitmap bmp=new Bitmap(50,100);
g=Graphics.FromImage(bmp);
SizeF rec=g.MeasureString(tmp,new Font("宋体",12));
int nwidth=(int)rec.Width;
int nheight=(int)rec.Height;
g.Dispose();
bmp.Dispose();
bmp=new Bitmap(nwidth,nheight);
g=Graphics.FromImage(bmp);
g.FillRectangle(new SolidBrush(Color.FromArgb(90, 126, 220)), new Rectangle(0,0,nwidth,nheight));
g.DrawString(tmp,new Font("宋体",12), new SolidBrush(Color.Yellow), new PointF(0, 0));
string fff=path+ @"tmp\validation.gif";
bmp.Save(fff,System.Drawing.Imaging.ImageFormat.Gif);
img.ImageUrl=fff;
return tmp;
string tmp;//文字
Random rnd=new Random();
tmp=rnd.Next().ToString().Substring(0,4);
Graphics g=null;
Bitmap bmp=new Bitmap(50,100);
g=Graphics.FromImage(bmp);
SizeF rec=g.MeasureString(tmp,new Font("宋体",12));
int nwidth=(int)rec.Width;
int nheight=(int)rec.Height;
g.Dispose();
bmp.Dispose();
bmp=new Bitmap(nwidth,nheight);
g=Graphics.FromImage(bmp);
g.FillRectangle(new SolidBrush(Color.FromArgb(90, 126, 220)), new Rectangle(0,0,nwidth,nheight));
g.DrawString(tmp,new Font("宋体",12), new SolidBrush(Color.Yellow), new PointF(0, 0));
string fff=path+ @"tmp\validation.gif";
bmp.Save(fff,System.Drawing.Imaging.ImageFormat.Gif);
img.ImageUrl=fff;
return tmp;
相关文章推荐
- python在图片写文字,产生随机验证码序列号
- fastdfs返回的url产生多余的group1路径,导致获取图片响应400
- 偶的小收获(关于验证码随机产生图片)
- ios移动开发navigationItem自带的返回按钮设置成自定义图片或者不显示父视图的标题文字
- 【wed】wed网页随机产生验证码图片(版本tomcat-8.0.14)
- 随机产生验证码图片---参考代码
- 由计算机产生0-9之间的随机整数,用户输入猜测的数据,统计用户猜测的次数。产生随机数可以使用Math.rangom()静态方法,该方法返回正的double类型浮点数位于(0.0 1.0】间。
- marquee控制文字或者图片等产生移动效果
- 图片与文字产生联动效果,外带不可用效果(disabled)
- javaweb注册的时候产生随机图片并且生成随机数
- ios开发如何让navigationItem自带的返回按钮设置成图片或者不显示文字
- 产生随机图片代码
- MVC把随机产生的字符串转换为图片
- 导航栏返回按钮替换图片去掉文字
- wed网页随机产生验证码图片(版本tomcat-8.0.14)
- PHP对接微信公众号,并实现返回给用户文字或图片或图文的内容。
- 一个产生随机图片验证码的示例
- 从表中随机返回n条记录,要求下次执行时产生不同结果集
- 导航条返回按钮的隐藏,修改图片或者文字
- 黑马程序员—产生随机图片