Public Sub AdjustImageSize(ByVal paraImg As Image, ByVal ParaIntWidth As Integer, ByVal ParaIntHeight As Integer, ByVal ParaStrSaveLoc As String)
'参数说明:paraImg 原始图象; ParaIntWidth 调整的宽度; ParaIntHeight 调整的高度; ParaStrSaveLoc 保存路径
Dim Bmp As New Bitmap(ParaIntWidth, ParaIntHeight)
Dim Gr As Graphics
Gr = Graphics.FromImage(Bmp)
'设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality
Gr.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
'下面这个也设成高质量
Gr.CompositingQuality = Drawing2D.CompositingQuality.HighSpeed
'下面这个设成High
Gr.InterpolationMode = Drawing2D.InterpolationMode.Low
'把原始图像绘制成上面所设置宽高的缩小图
Dim rectDestination As Rectangle = New System.Drawing.Rectangle(0, 0, ParaIntWidth, ParaIntHeight)
Gr.DrawImage(paraImg, rectDestination, 0, 0, paraImg.Width, paraImg.Height, GraphicsUnit.Pixel)
Dim Ep As Imaging.EncoderParameters = New Imaging.EncoderParameters(1)
Ep.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100)
Dim myImageCodecInfo As ImageCodecInfo
myImageCodecInfo = GetEncoderInfo("image/jpeg")
If myImageCodecInfo Is Nothing Then
Bmp.Save(ParaStrSaveLoc, Imaging.ImageFormat.Jpeg)
Else
Bmp.Save(ParaStrSaveLoc, myImageCodecInfo, Ep)
End If
Bmp.Dispose()
End Sub
Public Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
Dim j As Integer
Dim encoders() As ImageCodecInfo
encoders = ImageCodecInfo.GetImageEncoders()
For j = 0 To encoders.Length - 1 '(j = 0; j < encoders.Length; ++j)
If encoders(j).MimeType = mimeType Then
Return encoders(j)
Else
Return Nothing
End If
Next
End Function