您的位置:首页 > 其它

产生随机图片,并返回图片内的文字

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: