VB.NET中怎么實(shí)現(xiàn)一個(gè)縮略圖案,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)公司是一家服務(wù)多年做網(wǎng)站建設(shè)策劃設(shè)計(jì)制作的公司,為廣大用戶提供了成都做網(wǎng)站、成都網(wǎng)站建設(shè),成都網(wǎng)站設(shè)計(jì),1元廣告,成都做網(wǎng)站選創(chuàng)新互聯(lián)建站,貼合企業(yè)需求,高性價(jià)比,滿足客戶不同層次的需求一站式服務(wù)歡迎致電。
VB.NET實(shí)現(xiàn)縮略圖代碼:
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 '檢驗(yàn)圖片類型================================================================= If vPicFile.PostedFile.FileName = "" Then Throw New NotSupportedException("文件為空,請(qǐng)您選擇上傳的圖片文件!") End If If Left(vPicFile.PostedFile.ContentType, 5) <> "image" Then Throw New NotSupportedException("文件格式不合法,請(qǐng)選取有效的圖片文件!" & 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 '檢驗(yàn)數(shù)量限制================================================================= '保存大文件================================================================= 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() '刪除臨時(shí)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
看完上述內(nèi)容,你們掌握VB.NET中怎么實(shí)現(xiàn)一個(gè)縮略圖案的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!