欢迎光临
我们一直在努力

制作最清晰缩略图的完整类-.NET教程,评论及其它

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

public class classuppic

private vpicfile as system.web.ui.htmlcontrols.htmlinputfile

private vsmallpicsize, vupfilesize as integer

private vuppicpath, vnewpicname, vtmppicname as string

private picmin, picmax, vpicmax as system.drawing.image

private picformat as system.drawing.imaging.imageformat

private minheight, minwidth as decimal

private myfile as io.file

public sub new(byval picfile as system.web.ui.htmlcontrols.htmlinputfile, byval uppictype as pictype)

vpicfile = picfile

vupfilesize = httpcontext.current.application("upfilesize")

select case uppictype

case pictype.face

vuppicpath = "upload/images/face"

vsmallpicsize = 150

vnewpicname = httpcontext.current.session("memberid") & "." & getrightbychar(vpicfile.postedfile.filename, ".")

case pictype.photo

vuppicpath = "upload/images/photo"

vsmallpicsize = 150

vnewpicname = system.guid.newguid.tostring() & "." & getrightbychar(vpicfile.postedfile.filename, ".")

case pictype.pic

vuppicpath = "upload/images/pic"

vsmallpicsize = 550

vnewpicname = system.guid.newguid.tostring() & "." & getrightbychar(vpicfile.postedfile.filename, ".")

end select

end sub

public function getsavedfilename() as string

检验图片类型=================================================================

if vpicfile.postedfile.filename = "" then

throw new notsupportedexception("文件为空,请您选择上传的图片文件!")

end if

if left(vpicfile.postedfile.contenttype, 5) <> "image" then

throw new notsupportedexception("文件格式不合法,请选取有效的图片文件!" & vpicfile.postedfile.contenttype)

end if

if vpicfile.postedfile.contentlength > vupfilesize then

dim maxnumber as decimal = vupfilesize / 1024 / 1024

throw new notsupportedexception("上传的图片文件太大,最大支持" & format(maxnumber, "##,##0") & "m!")

end if

检验数量限制=================================================================

保存大文件=================================================================

vpicfile.postedfile.saveas(httpcontext.current.server.mappath(vuppicpath & "/max/") & vnewpicname)

vpicfile.dispose()

缩略图片文件=================================================================

picmax = system.drawing.image.fromfile(httpcontext.current.server.mappath(vuppicpath & "/max/") & vnewpicname)

if not (picmax.rawformat is picformat.gif or picmax.rawformat is picformat.png) then

if picmax.height > vsmallpicsize or picmax.width > vsmallpicsize then

vtmppicname = system.guid.newguid.tostring() & ".png"

vpicmax = picmax

picmax.save(httpcontext.current.server.mappath(vuppicpath & "/max/") & vtmppicname, picformat.png)

vpicmax.dispose()

picmax = system.drawing.image.fromfile(httpcontext.current.server.mappath(vuppicpath & "/max/") & vtmppicname)

end if

end if

保存小文件=================================================================

getminpic(picmax).save(httpcontext.current.server.mappath(vuppicpath & "/min/") & vnewpicname, picformat.jpeg)

picmax.dispose()

删除临时png文件=================================================================

if vtmppicname <> "" then myfile.delete(httpcontext.current.server.mappath(vuppicpath & "/max/") & vtmppicname)

return vnewpicname

end function

private function getminpic(byval maxpic as system.drawing.image) as system.drawing.image

if maxpic.height > vsmallpicsize or maxpic.width > vsmallpicsize then

if maxpic.height > maxpic.width then

minwidth = maxpic.width / (maxpic.height / vsmallpicsize)

minheight = vsmallpicsize

else

minwidth = vsmallpicsize

minheight = maxpic.height / (maxpic.width / vsmallpicsize)

end if

return maxpic.getthumbnailimage(cint(minwidth), cint(minheight), nothing, new system.intptr())

else

return maxpic

end if

end function

enum pictype

face = 1

photo = 2

pic = 3

end enum

private function getrightbychar(byval strvalue as string, byval charvalue as string) as string

dim mystr() as string = split(strvalue, charvalue)

return mystr(mystr.length – 1)

end function

end class

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

相关推荐

  • 暂无文章