日期:2011-08-09 浏览次数:21050 次
<%@ 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);最后,我们实现渐变效果。 <% ' 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
%>
Function NewthumbSize(currentwidt