2010年6月20日 星期日

ASP VB.NET 縮圖語法(圖片處理)

Function ASP_IMAGE(ByVal durl As String, ByVal surl As String, ByVal w As Integer, ByVal h As Integer)
'ASP.NET 縮圖功能
Dim image As System.Drawing.Image
'Dim anewimage As System.Drawing.Bitmap
Dim callb As System.Drawing.Image.GetThumbnailImageAbort
Dim width, height, newwidth, newheight As Integer

image = System.Drawing.Image.FromFile(durl)
width = image.Width
height = image.Height

If Not (width < w And height < h) Then
If width > height Then
h = w * height / width
Else
w = h * width / height
End If
End If

Dim img As System.Drawing.Bitmap = New System.Drawing.Bitmap(w, h)
Dim graphic As Graphics = Graphics.FromImage(img)
graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
graphic.DrawImage(image, 0, 0, w, h)

image.Dispose()

img.Save(surl, System.Drawing.Imaging.ImageFormat.Jpeg)

img.Dispose()
graphic.Dispose()

End Function

沒有留言:

張貼留言