Hello,
Another way would be that you use the
Image
object of the
System.Drawing
namespace.
You could load the image and process the image by just playing with the EncoderParameters and save it to a file or a stream:
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
public void ProcessImage(string inputFilename, string outputFilename)
{
Image inputImage = Image.FromFile(inputFilename);
ImageCodecInfo imageCodecInfo = GetEncoderInfo("image/jpeg");
Encoder qualityParamIdentifier = Encoder.Quality;
EncoderParameters encoderParameters = new EncoderParameters(1);
EncoderParameter qualityParam = new EncoderParameter(qualityParamIdentifier, 25L);
encoderParameters.Param[0] = qualityParam;
inputImage.Save(outputFilename, imageCodecInfo, encoderParameters);
}
Here are more informations about the Image.Save and the EncoderParameters defining the image quality:
http://msdn.microsoft.com/en-us/library/ytz20d80.aspx[
^].
Hope this helps.
Best regards, have a nice day and happy coding,
Stops