网站首页 > 网络编程教程 > ASP.NET教程 > ASP.net生成文字图片

ASP.net生成文字图片

  • 作者:互联网
  • 时间:2009-06-30 15:33:43

   string _FontName = Request["fontname"].ToString();
   int _FontSize = Co***rt.ToInt16(Request["fontsize"]);
   string _ShowName = Request["str"].ToString();
  
  
   Bitmap objBitmap = null;
   Graphics g = null ;
  
   Font stringFont = new Font(_FontName, _FontSize, Fo***tyle.Bold );
   StringFormat stringFormat = new StringFormat();
   st***gFormat.FormatFlags = St***gFormatFlags.NoWrap;


   try
   {
    objBitmap = new Bitmap(1,1);
    g = Gr***ics.FromImage(objBitmap);
    SizeF stringSize = g.***sureString(_ShowName, stringFont);
    int nWidth = (int)st***gSize.Width;
    int nHeight = (int)st***gSize.Height;
    g.***pose();
    ob***tmap.Dispose();

    objBitmap = new Bitmap(nWidth,nHeight);
    g = Gr***ics.FromImage(objBitmap);
    g.***lRectangle(new SolidBrush(Co***.Yellow), new Rectangle(0,0,nWidth,nHeight));
    g.***tRenderingHint = Te***enderingHint.AntiAlias;
    g.***wString(_ShowName, stringFont, new SolidBrush(Co***.Black), new PointF(0, 0), stringFormat);  
    ob***tmap.Save(Re***nse.OutputStream, Im***Format.Gif);
   }
   catch (Exception ee)
   {
    Re***nse.Write(ee***String());
   }
   finally
   {
    if (null != g) g.***pose();
    if (null != objBitmap) ob***tmap.Dispose();
    Re***nse.End();
   }