<summary>
Save the picture by the specified compression quality and format (Microsoft's Image.Save method saves the image compression quality to 75)
</summary>
<param name= "Sourceimage" > Image object of the picture you want to save </param>
<param name= "Savepath" > images to save the absolute path </param>
<param name= "Imagequalityvalue" > Picture to save the compression quality, the value of this parameter is an integer of 1 to 100, the larger the value, the better the quality of the Save </param>
<returns> save succeeded, return true; return false</returns>
public bool Saveimageforspecifiedquality (System.Drawing.Image sourceimage, string savepath, int imagequalityvalue)
{
The following code sets the compression quality when the picture is saved
EncoderParameters encoderparameters = new EncoderParameters ();
Encoderparameter encoderparameter = new Encoderparameter (System.Drawing.Imaging.Encoder.Quality, Imagequalityvalue) ;
Encoderparameters.param[0] = Encoderparameter;
Try
{
imagecodecinfo[] Imagecodecinfoarray = Imagecodecinfo.getimageencoders ();
ImageCodecInfo jpegimagecodecinfo = null;
for (int i = 0; i < imagecodecinfoarray.length; i++)
{
if (Imagecodecinfoarray[i]. Formatdescription.equals ("JPEG"))
{
Jpegimagecodecinfo = Imagecodecinfoarray[i];
Break
}
}
Sourceimage.save (Savepath, Jpegimagecodecinfo, encoderparameters);
return true;
}
Catch
{
return false;
}
}
Example code for saving a picture by a specified quality in C # 24-bit depth