Imports System.Drawing.Imaging
Sub SaveJPG()
Dim Image as Bitmap = New Bitmap(OrigianalImageFile)
'設定壓縮品質90檔案大小約是100的一半 但是畫質還是很不錯
Dim quality As Integer = 90
Dim qualityParam As New EncoderParameter(Encoder.Quality, quality)
'取得編碼格式
Dim jgpEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Jpeg)
Dim encoderParams As New EncoderParameters(1)
encoderParams.Param(0) = qualityParam
Image.Save(NewImageFile, jgpEncoder, encoderParams)
End Sub
'取得編碼格式的副程式
Private Function GetEncoder(ByVal format As ImageFormat) As ImageCodecInfo
Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageDecoders()
Dim codec As ImageCodecInfo
For Each codec In codecs
If codec.FormatID = format.Guid Then
Return codec
End If
Next codec
Return Nothing
End Function
參考資料:MSDN
留言