ASP.net生成文字图片

来源:互联网 发布:二手货如何在淘宝上卖 编辑:程序博客网 时间:2024/05/29 13:53
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
string _FontName = Request["fontname"].ToString();
int _FontSize = Convert.ToInt16(Request["fontsize"]);
string _ShowName = Request["str"].ToString();


Bitmap objBitmap = null;
Graphics g = null ;

Font stringFont = new Font(_FontName, _FontSize, FontStyle.Bold );
StringFormat stringFormat = new StringFormat();
stringFormat.FormatFlags = StringFormatFlags.NoWrap;


try
{
objBitmap = new Bitmap(1,1);
g = Graphics.FromImage(objBitmap);
SizeF stringSize = g.MeasureString(_ShowName, stringFont);
int nWidth = (int)stringSize.Width;
int nHeight = (int)stringSize.Height;
g.Dispose();
objBitmap.Dispose();

objBitmap = new Bitmap(nWidth,nHeight);
g = Graphics.FromImage(objBitmap);
g.FillRectangle(new SolidBrush(Color.Yellow), new Rectangle(0,0,nWidth,nHeight));
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.DrawString(_ShowName, stringFont, new SolidBrush(Color.Black), new PointF(0, 0), stringFormat);  
objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
catch (Exception ee)
{
Response.Write(ee.ToString());
}
finally
{
if (null != g) g.Dispose();
if (null != objBitmap) objBitmap.Dispose();
Response.End();
}

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>