![]() |
|
||||||||||||||
| | 网站首页 | 技术教程 | 网站开发 | 程序下载 | 言情小说 | 法律咨询 | Firefox | 两性故事 | 健康知识 | 网络游戏 | 免费论文 | | ||
|
||
|
|||||
| ASP.NET图象处理详解 | |||||
|
一、System.Drawing的使用以下的举例将演示在内存中生成一张图片,然后,将这张图片通过网页显示出来。需要了解的是,我们这里输出的不是HTML效果,而是实实在在的图片(图象),我们可以使用“另存为…”将输出图象保存起来。 我们先来看看效果:
在以上代码中,我们看到和数据库程序不同,这里专门引入了图象处理的名字空间system.drawing等。程序首先清空了Response,确保没有输出;然后,程序建立了一个120乘30大的BMP图象,再在这个基础上建立一个新图象,建立图象以后,我们首先“画”出了字符串“看见了吗”,该字符串为16大粗黑体,颜色为白色,位置为(2,4);最后,我们实现渐变效果。 二、读取和改变图象文件大小读取图片?直接使用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("wi |
|||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 最新热点 | 最新推荐 | 相关文章 | ||
| ASP.NET可交互式位图窗体设计 |
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | Baidu News | Google Map | | |||
|