我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > net专区 > ASP.NET图象处理详解(2)
热门文章排行
热门文章排行 检查email地址格式的代码(01-11)
PHP操作文件问答(01-11)
PHP安装攻略:安装并配置PHP(10-23)
PHP的十个高级技巧 4(10-23)
关于APE的介绍、播放及制作(03-22)
精采文章排行
精采文章排行 ASP.NET与MySQL数据库简明图示入门教(11-16)
ASP.NET与MySQL数据库简明图示入门教(11-16)
ASP.NET 链接数据库基础(11-16)
webconfig的设置节点说明(11-16)
部署ASP.NET的三大技术(上)(11-16)
技术专题推荐
网管论坛交流
 

ASP.NET图象处理详解(2) 

作者:佚名   来源:Linux 宝库   点击:   日期:2006-12-22

  二、读取和改变图象文件大小 
  
  读取图片?直接使用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)
   g.dispose()
   imgOutput.dispose()
   end sub
   </script>
  
   <%
   response.clear
   if request("src")="" or request("height")="" or request("width")="" then
   call sendError()
   else
   if file.exists(server.mappath(request("src"))) then
   call sendFile()
   else
   call sendError()
   end if
   end if
   response.end
   %> 
  
  在以上的程序中,我们看到两个函数,一个是SendFile,这一函数主要功能为显示服务器上的图片,该图片的大小通过Width和Height设置,同时,程序会自动检测图片类型;另外一个是SendError,这一函数的主要功能为服务器上的图片文件不存在时,显示错误信息,这里很有趣,错误信息也是通过图片给出的(如图):
  
   
  
  以上的程序显示图片并且改变图片大小,现在,我们将这个程序进一步,显示图片并且保持图片的长宽比例,这样,和实际应用可能比较接近,特别是需要制作电子相册或者是图片网站的时候比较实用。我们先来看主要函数:
  
   Function NewthumbSize(currentwidth, currentheight)
   dim tempMultiplier as Double
   if currentheight > currentwidth then
   tempMultiplier = 200 / currentheight
   Else
   tempMultiplier = 200 / currentwidth
   end if
   dim NewSize as New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier))
   return NewSize
   End Function 
   
   
  以上程序是增加的一个函数NewthumbSize,该函数专门处理改变一会的图片大小,这个图片的长宽和原图片的长宽保持相同比例。其他部分请参考上文程序代码。






文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·给你的FileSystemObject对象加把锁 ·在 Web 页上使用条件数值格式
·连接数据库查询手册(不仅仅适用于asp) ·警惕"给你的FileSystemObject对象加把锁"
·用ASP做全文检索 ·如何把ASP编写成DLL

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。