This documentation is archived and is not being maintained.

Encoder.Quality Field

Represents an Encoder object that is initialized with the globally unique identifier for the quality parameter category.

Namespace: System.Drawing.Imaging
Assembly: System.Drawing (in system.drawing.dll)

public static readonly Encoder Quality
public static final Encoder Quality
public static final var Quality : Encoder
Not applicable.

The Quality category specifies the level of compression for an image. When used to construct an EncoderParameter, the range of useful values for the quality category is from 0 to 100. The lower the number specified, the higher the compression and therefore the lower the quality of the image. Zero would give you the lowest quality image and 100 the highest.

The following example creates a Bitmap object from a BMP file. The code saves the bitmap to three JPEG files, each with a different quality level.

using System;
using System.Drawing;
using System.Drawing.Imaging;
class Example_SetJPEGQuality
    public static void Main()
        Bitmap myBitmap;
        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;
        // Create a Bitmap object based on a BMP file.
        myBitmap = new Bitmap("Shapes.bmp");
        // Get an ImageCodecInfo object that represents the JPEG codec.
        myImageCodecInfo = GetEncoderInfo("image/jpeg");
        // Create an Encoder object based on the GUID
        // for the Quality parameter category.
        myEncoder = 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);
        // Save the bitmap as a JPEG file with quality level 25.
        myEncoderParameter = new EncoderParameter(myEncoder, 25L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("Shapes025.jpg", myImageCodecInfo, myEncoderParameters);
        // Save the bitmap as a JPEG file with quality level 50.
        myEncoderParameter = new EncoderParameter(myEncoder, 50L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("Shapes050.jpg", myImageCodecInfo, myEncoderParameters);
        // Save the bitmap as a JPEG file with quality level 75.
        myEncoderParameter = new EncoderParameter(myEncoder, 75L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        myBitmap.Save("Shapes075.jpg", myImageCodecInfo, myEncoderParameters);
    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;

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0