ddc
联网
平面设计 画册 VI欣赏 包装 CG-插画 搜索 个人网页 Alexa排名 CSS 建站资源 下载专区 JS特效 品牌服装 服装院校 专题欣赏 SEO 图标欣赏 专题
网站建设 域名注册 网站建设 虚拟主机 广州网站设计 域名注册 广州网站建设 上海网站建设 虚拟主机 广州网页设计 虚拟主机 域名注册 acg王国 ACG玩家 品牌设计 上海网站建设
求创科技
网站建设
中国互联
素材出售
中国设计秀
中资源
当前位置:网络学院首页 >> 编程开发 >> .net >> ASP.NET中图象处理过程详解

ASP.NET中图象处理过程详解 (1)

来源:中国设计秀    作者:jorux    点击:98     加入收藏    发表评论
0
顶一下
关键字:asp.net .net
   在使用ASP的时候,我们时常要借助第三方控件来实现一些图象功能。而现在,ASP.NET的推出,我们已经没有必要再使用第三方控件来实现,因为ASP.NET 已经具有强大的功能来实现一些图象处理。现在,我们就来看看怎样使用ASP.NET的这一强大功能。
  
  一、System.Drawing的使用
  以下的举例将演示在内存中生成一张图片,然后,将这张图片通过网页显示出来。需要了解的是,我们这里输出的不是HTML效果,而是实实在在的图片(图象),我们可以使用“另存为…”将输出图象保存起来。
  我们先来看看效果:
  
  我们看到,这张图片是一个渐变背景上有“看见了吗”几个字,当然,这个效果在PhotoShop等图象处理软件里面很容易实现,但是,一些与数据库结合的应用我们不可能将所有图片都事先设计出来,这时候,利用ASP.NET来实现这些功能就显得很重要了。我们来看源代码:
  <%@ page language="vb" contenttype="image/jpeg" %>
  <%@ import namespace="system.drawing" %>
  <%@ import namespace="system.drawing.imaging" %>
  <%@ import namespace="system.drawing.drawing2d" %>
  
  <%
  '清空Response
  response.clear
  
  '建立一个120*30大小,24bit的BMP图象;
  dim imgOutput as New bitmap(120, 30, pixelformat.format24bpprgb)
  
  '根据以上BMP建立一个新图象;
  dim g as graphics = graphics.fromimage(imgOutput)
  
  g.clear(color.Green)
  g.smoothingMode = smoothingMode.antiAlias
  
  g.drawString("看见了吗?", New font("黑体",16,fontstyle.bold),new SolidBrush(Color.White),New pointF(2,4))
  
  g.FillRectangle(New linearGradientBrush(New point(0,0), New point(120,30), color.fromArgb(0,0,0,0),color.fromArgb(255,255,255,255)),0,0,120,30)
  
  imgOutput.save(response.outputstream, imageformat.jpeg)
  
  g.dispose()
  imgOutput.dispose()
  response.end
  %>
  在以上代码中,我们看到和数据库程序不同,这里专门引入了图象处理的名字空间system.drawing等。程序首先清空了Response,确保没有输出;然后,程序建立了一个120乘30大的BMP图象,再在这个基础上建立一个新图象,建立图象以后,我们首先“画”出了字符串“看见了吗”,该字符串为16大粗黑体,颜色为白色,位置为(2,4);最后,我们实现渐变效果。
  以上举例很简单,但是如果和数据库结合,我们可以实现很多使用ASP可能不敢想的效果。
  
  二、读取和改变图象文件大小
  读取图片?直接使用HTML不就可以了?当然可以,我们这里只是提供一种选择和方法来实现这一功能,具体这一功能的使用,我们可能需要在实践中更多的学习。先来看程序源代码:
  <% ' import all relevant namespaces %>
  <%@ import namespace="System" %>
  <%@ import namespace="System.Drawing" %>
  <%@ import namespace="System.Drawing.Imaging" %>
  <%@ import namespace="System.IO" %>
  
  <script runat="server">
  Sub sendFile()
  dim g as System.Drawing.Image = System.Drawing.Image.FromFile(server.mappath(request("src")))
  dim thisFormat=g.rawformat
  dim imgOutput as New Bitmap(g, cint(request("width")), cint(request("height")))
  if thisformat.equals(system.drawing.imaging.imageformat.Gif) then
  response.contenttype="image/gif"
  else
  response.contenttype="image/jpeg"
  end if
  imgOutput.save(response.outputstream, thisformat)
  g.dispose()
  imgOutput.dispose()
  end sub
  
  Sub sendError()
  dim imgOutput as New bitmap(120, 120, pixelformat.format24bpprgb)
  dim g as graphics = graphics.fromimage(imgOutput)
  g.clear(color.yellow)
  g.drawString("错误!", New font("黑体",14,fontstyle.bold),systembrushes.windowtext, New pointF(2,2))
  response.contenttype="image/gif"
  imgOutput.save(response.outputstream, imageformat.gif)
[1] [2] [3]
2008-09-24 10:33:00    出处:中国设计秀cnwebshow.com
Google
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明 | 网站公告 | 友情链接 | 留言 | 旧版入口