
Originally Posted by
jareck
please can you share the code
i really need the part of setting the image quality...
Hi, I have the source files (no solution file) for download in CodeProjects website. Also I am providing the part that sets jpeg file quality. Note, you can only set jpeg file quality not the other file formats since they don’t support image quality property.
vb Code:
If myImageFormat IsNot ImageFormat.Jpeg Then
'For all other formats
img.Save(fileName, myImageFormat)
Else
'For jpeg format
Dim codecInfo As ImageCodecInfo = GetEncoderInfo("image/jpeg")
If codecInfo IsNot Nothing Then
img.Save(fileName, codecInfo, MenuForm.GetEncoderParameters(My.Settings.Quality))
End If
End If
vb Code:
Private Shared Function GetEncoderParameters(ByVal quality As Integer) As EncoderParameters
Dim myEncoder As Imaging.Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameters As EncoderParameters
' Create an Encoder object based on the GUID
' for the Quality parameter category.
myEncoder = Imaging.Encoder.Quality
' Create an EncoderParameters object.
' An EncoderParameters object has an array of EncoderParameter
' objects. In this case, there is only one
' EncoderParameter object in the array.
myEncoderParameters = New EncoderParameters(1)
' Sets the quality parameter.
myEncoderParameter = New EncoderParameter(myEncoder, quality)
myEncoderParameters.Param(0) = myEncoderParameter
Return myEncoderParameters
End Function