/// <summary>
        
/// 根据指定参数返回BitMap对象
        
/// 引用如下:
        
/// using System.Drawing;
        
/// 调用例子如下:
        
///     eg1、保存为图象文件为
        
///     Bitmap srBmp = srBitmap(srs);
        
///     srBmp.Save(Directory.GetCurrentDirectory() + "\\srs.gif", System.Drawing.Imaging.ImageFormat.Gif);
        
///     srBmp.Dispose();
        
///     eg2。网页中调用方式如下
        
///     Bitmap srBmp = srBitmap(srs);
        
///     System.IO.MemoryStream srMS = new System.IO.MemoryStream();
        
///     srBmp.Save(srMS,System.Drawing.Imaging.ImageFormat.Gif);
        
///     Response.ClearContent();
        
///     Response.ContentType = "image/gif";
        
///     Response.BinaryWrite(srMS.ToArray());
        
///     srBmp.Dispose();
        
/// </summary>
        
/// <param name="srs"></param>
        
/// <returns></returns>

        
public static Bitmap srBitmap(string srs)
        {
            
//定义图片弯曲的角度
            int srseedangle = 45;
            
//定义图象
            Bitmap srBmp = new Bitmap(srs.Length*20,30);
            
//画图
            Graphics srGraph = Graphics.FromImage(srBmp);
            
//清空图象
            srGraph.Clear(Color.AliceBlue);
            
//给图象画边框
            srGraph.DrawRectangle(new Pen(Color.Black,0),0,0,srBmp.Width-1,srBmp.Height-1);
            
//定义随即数
            Random srRandom = new Random();
            
//定义画笔
            Pen srPen = new Pen(Color.LightGray,0);
            
//画噪点
            for (int i = 0; i < 100; i++)
            {
                srGraph.DrawRectangle(srPen,srRandom.Next(
1,srBmp.Width-2),srRandom.Next(1,srBmp.Height-2),1,1);
            }
            
//将字符串转化为字符数组
            char[] srchars = srs.ToCharArray();
            
//封状文本
            StringFormat srFormat = new StringFormat(StringFormatFlags.NoClip);
            
//设置文本垂直居中
            srFormat.Alignment = StringAlignment.Center;
            
//设置文本水平居中
            srFormat.LineAlignment = StringAlignment.Center;
            
//定义字体颜色
            Color[] srColors ={ Color.Black,Color.Red,Color.DarkBlue,Color.Blue,Color.Orange,Color.Brown,Color.DarkCyan,Color.Purple};
            
//定义字体
            string[] srFonts ="Verdana""Microsoft Sans Serif""Comic Sans MS""Arial""宋体" };
            
//循环画出每个字符
            for (int i = 0, j = srchars.Length; i < j; i++)
            {
                
//定义字体 参数分别为字体样式 字体大小 字体字形
                Font srFont = new Font(srFonts[srRandom.Next(5)], srRandom.Next(12,20), FontStyle.Regular);
                
//填充图形
                Brush srBrush = new SolidBrush(srColors[srRandom.Next(7)]);
                
//定义坐标
                Point srPoint = new Point(1616);
                
//定义倾斜角度
                float srangle = srRandom.Next(-srseedangle, srseedangle);
                
//倾斜
                srGraph.TranslateTransform(srPoint.X, srPoint.Y);
                srGraph.RotateTransform(srangle);
                
//填充字符
                srGraph.DrawString(srchars[i].ToString(),srFont,srBrush,1,1,srFormat);
                
//回归正常
                srGraph.RotateTransform(-srangle);
                srGraph.TranslateTransform(
2,-srPoint.Y);
            }
            srGraph.Dispose();
            
return srBmp;
        }

转http://blog.csdn.net/srnpr/archive/2007/11/08/1875187.aspx

相关文章:

  • 2021-12-03
猜你喜欢
  • 2021-06-15
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-05-29
相关资源
相似解决方案