16,554
社区成员
发帖
与我相关
我的任务
分享
'定義
Shared htmimes As New Hashtable
'初始化
#Region "htmimes[.jpe]=image/jpeg"
Shared Sub New()
htmimes(".jpe") = "image/jpeg"
htmimes(".gif") = "image/gif"
htmimes(".jpeg") = "image/jpeg"
htmimes(".jpg") = "image/jpeg"
htmimes(".png") = "image/png"
htmimes(".tif") = "image/tiff"
htmimes(".tiff") = "image/tiff"
htmimes(".bmp") = "image/bmp"
End Sub
#End Region
Private Shared Function GetCodecInfo(ByVal mimeType As String) As ImageCodecInfo
Dim CodecInfo As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
For Each ici As ImageCodecInfo In CodecInfo
If ici.MimeType = mimeType Then
Return ici
End If
Next
Return Nothing
End Function
Private Sub ThumbnailImage(ByVal newimage As Image, ByVal intNewWidth As Integer, ByVal intNewHeight As Integer, ByVal mFileExtName As String, ByVal level As Integer, ByVal SavePath As String)
Try
' Dim newImage As Image = Me.PictureBox1.Image
Dim ici As ImageCodecInfo = GetCodecInfo(DirectCast(htmimes(mFileExtName), String))
Dim parameters As New EncoderParameters(1)
parameters.Param(0) = New EncoderParameter(Encoder.Quality, CLng(level))
Dim objNewBitMap As New Bitmap(intNewWidth, intNewHeight, PixelFormat.Format32bppArgb)
'从指定的 Image 对象创建新 Graphics 对象
Dim objGraphics As Graphics = Graphics.FromImage(objNewBitMap)
'清除整个绘图面并以透明背景色填充
objGraphics.Clear(Color.Transparent)
'在指定位置并且按指定大小绘制 原图片 对象
objGraphics.DrawImage(newimage, New Rectangle(0, 0, intNewWidth, intNewHeight))
objNewBitMap.Save(SavePath, ici, parameters)
objNewBitMap.Dispose()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub