共用方式為


EncoderParameters 建構函式

定義

初始化 EncoderParameters 類別的新執行個體,這個執行個體可以含有指定數目的 EncoderParameter 物件。

多載

EncoderParameters()

初始化 EncoderParameters 類別的新執行個體,這個執行個體可以含有一個 EncoderParameter 物件。

EncoderParameters(Int32)

初始化 EncoderParameters 類別的新執行個體,這個執行個體可以含有指定數目的 EncoderParameter 物件。

EncoderParameters()

來源:
EncoderParameters.cs
來源:
EncoderParameters.cs
來源:
EncoderParameters.cs

初始化 EncoderParameters 類別的新執行個體,這個執行個體可以含有一個 EncoderParameter 物件。

public:
 EncoderParameters();
public EncoderParameters ();
Public Sub New ()

範例

下列程式代碼範例示範如何建立和使用 EncoderParameters 物件。 若要執行此範例,請將程式代碼貼到 Windows Form 中,並從表單的建構函式呼叫 VaryQualityLevel 方法。 此範例需要名為 TestPhoto.jpg 的映像檔位於 c:\

private void VaryQualityLevel()
{
    // Get a bitmap.
    Bitmap bmp1 = new Bitmap(@"c:\TestPhoto.jpg");
    ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);

    // Create an Encoder object based on the GUID
    // for the Quality parameter category.
    System.Drawing.Imaging.Encoder myEncoder =
        System.Drawing.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.
    EncoderParameters myEncoderParameters = new EncoderParameters(1);

    EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
    myEncoderParameters.Param[0] = myEncoderParameter;
    bmp1.Save(@"c:\TestPhotoQualityFifty.jpg", jpgEncoder, myEncoderParameters);

    myEncoderParameter = new EncoderParameter(myEncoder, 100L);
    myEncoderParameters.Param[0] = myEncoderParameter;
    bmp1.Save(@"c:\TestPhotoQualityHundred.jpg", jpgEncoder, myEncoderParameters);

    // Save the bitmap as a JPG file with zero quality level compression.
    myEncoderParameter = new EncoderParameter(myEncoder, 0L);
    myEncoderParameters.Param[0] = myEncoderParameter;
    bmp1.Save(@"c:\TestPhotoQualityZero.jpg", jpgEncoder, myEncoderParameters);
}
Private Sub VaryQualityLevel()
    ' Get a bitmap.
    Dim bmp1 As New Bitmap("c:\TestPhoto.jpg")
    Dim jpgEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Jpeg)

    ' Create an Encoder object based on the GUID
    ' for the Quality parameter category.
    Dim myEncoder As System.Drawing.Imaging.Encoder = System.Drawing.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.
    Dim myEncoderParameters As New EncoderParameters(1)

    Dim myEncoderParameter As New EncoderParameter(myEncoder, 50&)
    myEncoderParameters.Param(0) = myEncoderParameter
    bmp1.Save("c:\TestPhotoQualityFifty.jpg", jpgEncoder, myEncoderParameters)

    myEncoderParameter = New EncoderParameter(myEncoder, 100&)
    myEncoderParameters.Param(0) = myEncoderParameter
    bmp1.Save("c:\TestPhotoQualityHundred.jpg", jpgEncoder, myEncoderParameters)

    ' Save the bitmap as a JPG file with zero quality level compression.
    myEncoderParameter = New EncoderParameter(myEncoder, 0&)
    myEncoderParameters.Param(0) = myEncoderParameter
    bmp1.Save("c:\TestPhotoQualityZero.jpg", jpgEncoder, myEncoderParameters)

End Sub
private ImageCodecInfo GetEncoder(ImageFormat format)
{
    ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

    foreach (ImageCodecInfo codec in codecs)
    {
        if (codec.FormatID == format.Guid)
        {
            return codec;
        }
    }
    
    return null;
}
Private Function GetEncoder(ByVal format As ImageFormat) As ImageCodecInfo

    Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()

    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

備註

有些 SaveSaveAdd 方法會接收 EncoderParameters 物件做為自變數。 GetEncoderParameterList 方法會傳回 EncoderParameters 物件。

適用於

EncoderParameters(Int32)

來源:
EncoderParameters.cs
來源:
EncoderParameters.cs
來源:
EncoderParameters.cs

初始化 EncoderParameters 類別的新執行個體,這個執行個體可以含有指定數目的 EncoderParameter 物件。

public:
 EncoderParameters(int count);
public EncoderParameters (int count);
new System.Drawing.Imaging.EncoderParameters : int -> System.Drawing.Imaging.EncoderParameters
Public Sub New (count As Integer)

參數

count
Int32

整數,這個整數指定 EncoderParameter 物件可以包含的 EncoderParameters 物件數目。

適用於