ASP上传图片并生成缩略图

2008/10/4 17:03:46 来源:互联网 【 】 浏览:7122次
sub upimages()
dim iname as string
if not (fileup.postedfile is nothing) then
dim namestr1 as string = (fileup.postedfile.filename)
if lcase(fileup.postedfile.contenttype.tostring()) = "image/pjpeg" or lcase(fileup.postedfile.contenttype.tostring()) = "image/jpg" then
dim j as integer = namestr1.lastindexof(".")
dim newname as string = namestr1.substring(j) 圖片得到後輟名
iname = cstr(now.tofiletimeutc) 隨機的文档名(不會重復)
dim newnames as string = iname + newname 重新組合文档名
dim i as integer = namestr1.lastindexof("\") + 1
dim namestr as string = namestr1.substring(i)
fileup.postedfile.saveas(server.mappath(imagelocal) + "\" + newnames) 保存文档到imagelocal文档夾
生成縮略圖()
dim image, simage as system.drawing.image
image = system.drawing.image.fromstream(fileup.postedfile.inputstream)得到原图
dim width as decimal = image.width过且过得到原图的宽
dim height as decimal = image.height得到原图的高
dim newwidth, newheight as integer
配置缩略图的高和宽
if (width > height) then
newwidth = 150
newheight = cint(height / width * 150)
else
newheight = 150
newwidth = cint(width / height * 150)
end if
simage = image.getthumbnailimage(newwidth, newheight, nothing, intptr.zero)
dim x as integer = simage.width / 2 - 30
dim y as integer = simage.height - 20
dim output as bitmap = new bitmap(simage)
dim g as graphics = graphics.fromimage(output)
給縮略圖加上版權信息()
dim fonts as new font("courier new", 9)
g.drawstring("版權信息", fonts, new solidbrush(color.red), x, y)
output.save(server.mappath("simagelocal") + "\s_" + newnames, system.drawing.imaging.imageformat.jpeg)
保存縮略圖到simagelocal文档夾
image1.visible=true;
image1.imageurl = "simagelocal" + "\s_" + newnames

else
label1.text = "請選擇jpg類型的圖片"

end if
end if
end sub
  • 上一篇文章:表单提交“GET”的用法(form任何提交的值都会在地址栏出现)
  • 下一篇文章:WINDOWS服务器的JSP安装与配置
    当前地址:https://dns2003.com:443/help/hlp_dtl.asp?nid=10000306
    更多帮助登录: http://www.dns2003.com/help
    业务请咨询E网时代客服部