欢迎光临
我们一直在努力

上传图片并生成缩略图-ASP教程,ASP应用

建站超值云服务器,限时71元/月

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 上传图片并生成缩略图-ASP教程,ASP应用
分享到: 更多 (0)