当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > ASP.net生成文字图片

ASP.NET
ASP.NET中Session丢失原因与解决方案小结
.net开发中的一些注意事项及小技巧
学习Asp.Net经常会用到的函数集
在.net App中集成COM组件的一些简单技巧
彻底放弃IIS让Apache也支持ASP.NET
[JS.IntelliSense]VS2007(Orcas) So Cool
Asp.net 2.0 ViewState原理
asp.net ajax 使用updatepanel进行更新后的提示
动态代理DynamicProxy 介绍
您可能不知道的.Net2.0小技巧
Asp.Net2.0技巧(续)
“黑盒测试管理”以外的编程经验片断
实例开发:ASP.NET创建网络相册
封装stream,在读写stream时提供事件通知
GIS开发随笔--GIS技术的一点理解和MapNet控件试验
利用隐藏帧打印url的方法比较
无刷新仿google波形扭曲彩色Asp.net验证码
存储过程编写经验和优化措施
编程技巧:.Net Framework
编程技巧OOPs:复制构造函数

ASP.NET 中的 ASP.net生成文字图片


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 47 ::
收藏到网摘: n/a

以下为程序代码:



string_FontName=Request["fontname"].ToString();
int_FontSize=Convert.ToInt16(Request["fontsize"]);
string_ShowName=Request["str"].ToString();

BitmapobjBitmap=null;
Graphicsg=null;

FontstringFont=newFont(_FontName,_FontSize,FontStyle.Bold);
StringFormatstringFormat=newStringFormat();
stringFormat.FormatFlags=StringFormatFlags.NoWrap;

try
{
objBitmap=newBitmap(1,1);
g=Graphics.FromImage(objBitmap);
SizeFstringSize=g.MeasureString(_ShowName,stringFont);
intnWidth=(int)stringSize.Width;
intnHeight=(int)stringSize.Height;
g.Dispose();
objBitmap.Dispose();

objBitmap=newBitmap(nWidth,nHeight);
g=Graphics.FromImage(objBitmap);
g.FillRectangle(newSolidBrush(Color.Yellow),newRectangle(0,0,nWidth,nHeight));
g.TextRenderingHint=TextRenderingHint.AntiAlias;
g.DrawString(_ShowName,stringFont,newSolidBrush(Color.Black),newPointF(0,0),stringFormat); 
objBitmap.Save(Response.OutputStream,ImageFormat.Gif);
}
catch(Exceptionee)
{
Response.Write(ee.ToString());
}
finally
{
if(null!=g)g.Dispose();
if(null!=objBitmap)objBitmap.Dispose();
Response.End();
}