新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:用ASP+制作图形

用ASP+制作图形

新客网 XKER.COM 2004-08-24 来源: 收藏本文
001 <% @Page Language="C#" %>002 <%
@Import Namespace="System.Drawing" %>003 <% @Import Namespace="System.IO" %>004 <% @Import Namespace="System.Drawing.Imaging" %
>005 <%006 Response.Expires = 0;007 Bitmap newBitmap = null;008 Graphics g = null ;009 010 string str2Render =
Request.QueryString.Get("HitCount");011 if (null == str2Render) str2Render = "no count
specified";012 string strFont = Request.QueryString.Get
("HitFontName");013 if (null ==
strFont) strFont = "Lucida Sans Unicode";014 015 int nFontSize =
12;016 try017 {018 nFontSize = Request.QueryString.Get("HitFontSize").ToInt32();019 }020 catch021 {022 // do nothing, just ignore023 }024 025 string strBackgroundColorname = Request.QueryString.Get("HitBackgroundColor");026 Color
clrBackground = Color.White;027 try028 {029 // Format in the URL: %23xxXXxx030
if (null != strBackgroundColorname)031
clrBackground = ColorTranslator.FromHTML(strBackgroundColorname);032 }033 catch034 {035 }036 037 string strFontColorName =
Request.QueryString.Get("HitFontColor");038 Color clrFont = Color.Black;039 try040 {041 // Format in the URL: %
23xxXXxx042 if (null != strFontColorName)043 clrFont = ColorTranslator.FromHTML
(strFontColorName);044 }045 catch046 {047 }048 049 try 050 {051 Font fontCounter = new Font(strFont, nFontSize);052 053 // calculate size of the string.054
newBitmap = new Bitmap(1,1,PixelFormat.Format32bppARGB);055 g = Graphics.FromImage(newBitmap);056 SizeF stringSize = g.MeasureString(str2Render,
fontCounter);057 int nWidth = (int)
stringSize.Width;058 int nHeight = (int)
stringSize.Height;059 g.Dispose();060 newBitmap.Dispose();061 062 newBitmap =
new Bitmap(nWidth,nHeight,PixelFormat.Format32bppARGB);063 g
= Graphics.FromImage(newBitmap);064 g.FillRectangle(new
SolidBrush(clrBackground), new Rectangle(0,0,nWidth,nHeight));065 066 g.DrawString
(str2Render, fontCounter, new SolidBrush(clrFont), 0, 0);067
068 MemoryStream tempStream = new MemoryStream();069 newBitmap.Save(tempStream,ImageFormat.PNG);070 071
Response.ClearContent();072 Response.ContentType = "image/png";073 Response.BinaryWrite
(tempStream.ToArray());074
Response.End();075 // newBitmap.Save
(Response.OutputStream, ImageFormat.PNG);076 // newBitmap.Save("o:\\TestApps\\TestServer\\test.png", ImageFormat.PNG) ;077 } 078 catch (Exception e)
079 {080
Response.Write(e.ToString());081 }082 finally 083 {084 if (null != g) g.Dispose();085 if (null != newBitmap) newBitmap.Dispose();086 }087 %>

收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐