您现在的位置是:首页
>
net framework ASP.NET图象处理详解[2]
ASP.NET图象处理详解[2] 二 读取和改变图象文件大小 读取图片?直接使用HTML不就可以了?当然可以 我们这里只是提供一种选择和方法来实现这一功能 具体这一功能的使用 我们可能需要在实践
ASP.NET图象处理详解[2]
![net framework ASP.NET图象处理详解[2]](http://img.zhputi.com/uploads/5e4c/5e4cab035ed50071208b23e810e2c6b447213.jpg)
二 读取和改变图象文件大小
读取图片?直接使用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( pixelformat format bpprgb) dim g as graphics = graphics fromimage(imgOutput) g clear(color yellow) g drawString( 错误! New font( 黑体 fontstyle bold) systembrushes windowtext New pointF( )) 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 这一函数的主要功能为服务器上的图片文件不存在时 显示错误信息 这里很有趣 错误信息也是通过图片给出的(如图)
lishixinzhi/Article/program/net/201311/14864 很赞哦! (1037)