国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

制作最清晰縮略圖的完整類(VB.NET版)

2024-07-10 13:00:44
字體:
來源:轉載
供稿:網友
先收集一些相關資源
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

轉自:http://guoblog.com/blogview.asp?logid=259

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 菏泽市| 疏勒县| 宜阳县| 原平市| 汪清县| 南漳县| 开江县| 柯坪县| 稷山县| 南川市| 天门市| 恩施市| 鹤山市| 宣恩县| 双牌县| 嫩江县| 呼图壁县| 兴仁县| 黄陵县| 浦县| 房山区| 江阴市| 贵南县| 磴口县| 龙南县| 石泉县| 同德县| 天水市| 晋州市| 江城| 临安市| 朔州市| 红河县| 彭州市| 平阳县| 马鞍山市| 湟中县| 讷河市| 长宁县| 宝兴县| 洪泽县|