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

ASP.NET
基于C#的接口基础教程之五
基于C#的接口基础教程之六
ASP.NET中数据库的操作初步----增加、删除、修改
从Internet上抓取指定URL的源码的方案(C#)
对C#中正则表达式的一些解读和总结
简述c#中对字符串进行分割的几种方法
ASP.NET中的事务处理和异常处理
用ASP.NET/C#连接Access和SQL Server数据库
ASP.NET 2.0中层次数据的处理
ASP.NET 2.0服务器控件之客户端功能
asp.net2.0 URL重写以及urlMappings问题(1)
asp.net2.0 URL重写以及urlMappings问题(2)
再议ASP.NET DataGrid控件中的“添加新行”功能
建立个人知识引擎的重要性
解析.Net框架下的XML编程技术
ASP.NET--制作功能完善的安装程序
Asp.net直接保存文件到客户端
.Net中消除Dll中的dependency
ASP.NET页面事件:顺序与回传详解
在ASP.NET+ORACLE添加数据记录并让ID自动增量

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 53 ::
收藏到网摘: 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();
}