动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 用ASP+制作图形(有了ASP+,不需要扩展图像组件啦!)

作者来源: 
阅读 4720 人次 , 2000-11-29 

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 %>

  
 本文TagsC#  组件  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:显示系统日志(ASP+)
· 下一篇:ASP.NET学习手记:验证用户表单输入
· 提取HTML代码中文字的C#函数
· 图片上传的Codebehind(自动生成所略图)
· Asp.net+Xml开发网络硬盘
· 十二、脚本元素、指令和预定义变量
· ASP.NET中利用存储过程实现模糊查询


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077