zoukankan      html  css  js  c++  java
  • 产生随机图片,并返回图片内的文字

    /// <summary>
            
    /// 产生随机图片,并返回图片内的文字
            
    /// </summary>
            
    /// <param name="img">要显示图片的控件</param>        
            
    /// <param name="path">图片显示的文字</param>

            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(90126220)), new Rectangle(0,0,nwidth,nheight));
                g.DrawString(tmp,
    new Font("宋体",12), new SolidBrush(Color.Yellow), new PointF(00));
                
    string fff=path+ @"tmp\validation.gif";
                bmp.Save(fff,System.Drawing.Imaging.ImageFormat.Gif);                
                img.ImageUrl
    =fff;
                
    return tmp;
  • 相关阅读:
    Seaslog高性能日志系统学习
    同步、异步与阻塞、非阻塞、协程
    SQL常用增删改查语句
    js里的document对象大全(DOM操作)
    php的cURL资源的初步使用
    hive学习笔记(初级)
    使用NSIS制作可执行程序的安装包
    C#设置一个控件可以鼠标拖动
    C#画图超出屏幕的部分无法显示的解决方法
    C#获取当前不同网卡对应的iP
  • 原文地址:https://www.cnblogs.com/aipeli/p/251775.html
Copyright © 2011-2022 走看看