EncoderParameter EncoderParameter EncoderParameter EncoderParameter Class

定義

用於將值或值的陣列傳遞至影像編碼器。Used to pass a value, or an array of values, to an image encoder.

public ref class EncoderParameter sealed : IDisposable
public sealed class EncoderParameter : IDisposable
type EncoderParameter = class
    interface IDisposable
Public NotInheritable Class EncoderParameter
Implements IDisposable
繼承
EncoderParameterEncoderParameterEncoderParameterEncoderParameter
實作

範例

下列程式碼範例示範如何建立EncoderParameter使用EncoderParameter建構函式。The following code example demonstrates how to create a EncoderParameter using the EncoderParameter constructor. 若要執行此範例中,貼上程式碼的 Windows Form 和呼叫VaryQualityLevel從表單的建構函式的方法。To run this example, paste the code into a Windows Form and call the VaryQualityLevel method from the form's constructor. 這個範例需要名為影像檔TestPhoto.jpg位於c:\This example requires an image file named TestPhoto.jpg located at 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 'VaryQualityLevel

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

備註

您也可以使用EncoderParameter物件,以接收特定參數的特定的影像編碼器所支援的可能值清單。You can also use an EncoderParameter object to receive a list of possible values supported by a particular parameter of a particular image encoder.

建構函式

EncoderParameter(Encoder, Byte) EncoderParameter(Encoder, Byte) EncoderParameter(Encoder, Byte) EncoderParameter(Encoder, Byte)

使用指定的 EncoderParameter 物件和一個不帶正負號的 8 位元整數,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and one unsigned 8-bit integer. 設定 ValueType 屬性為 ValueTypeByte,並設定 NumberOfValues 屬性為 1。Sets the ValueType property to ValueTypeByte, and sets the NumberOfValues property to 1.

EncoderParameter(Encoder, Byte, Boolean) EncoderParameter(Encoder, Byte, Boolean) EncoderParameter(Encoder, Byte, Boolean) EncoderParameter(Encoder, Byte, Boolean)

使用指定的 EncoderParameter 物件和一個 8 位元值,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and one 8-bit value. 設定 ValueType 屬性為 ValueTypeUndefinedValueTypeByte,並設定 NumberOfValues 屬性為 1。Sets the ValueType property to ValueTypeUndefined or ValueTypeByte, and sets the NumberOfValues property to 1.

EncoderParameter(Encoder, Byte[]) EncoderParameter(Encoder, Byte[]) EncoderParameter(Encoder, Byte[]) EncoderParameter(Encoder, Byte[])

使用指定的 EncoderParameter 物件和不帶正負號的 8 位元整數的陣列,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and an array of unsigned 8-bit integers. 設定 ValueType 屬性為 ValueTypeByte,並設定 NumberOfValues 屬性為陣列中的元素數目。Sets the ValueType property to ValueTypeByte, and sets the NumberOfValues property to the number of elements in the array.

EncoderParameter(Encoder, Byte[], Boolean) EncoderParameter(Encoder, Byte[], Boolean) EncoderParameter(Encoder, Byte[], Boolean) EncoderParameter(Encoder, Byte[], Boolean)

使用指定的 EncoderParameter 物件和位元組的陣列,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and an array of bytes. 設定 ValueType 屬性為 ValueTypeUndefinedValueTypeByte,並設定 NumberOfValues 屬性為陣列中的元素數目。Sets the ValueType property to ValueTypeUndefined or ValueTypeByte, and sets the NumberOfValues property to the number of elements in the array.

EncoderParameter(Encoder, Int16) EncoderParameter(Encoder, Int16) EncoderParameter(Encoder, Int16) EncoderParameter(Encoder, Int16)

使用指定的 EncoderParameter 物件和一個 16 位元整數,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and one, 16-bit integer. 設定 ValueType 屬性為 ValueTypeShort,並設定 NumberOfValues 屬性為 1。Sets the ValueType property to ValueTypeShort, and sets the NumberOfValues property to 1.

EncoderParameter(Encoder, Int16[]) EncoderParameter(Encoder, Int16[]) EncoderParameter(Encoder, Int16[]) EncoderParameter(Encoder, Int16[])

使用指定的 EncoderParameter 物件和 16 位元整數的陣列,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and an array of 16-bit integers. 設定 ValueType 屬性為 ValueTypeShort,並設定 NumberOfValues 屬性為陣列中的元素數目。Sets the ValueType property to ValueTypeShort, and sets the NumberOfValues property to the number of elements in the array.

EncoderParameter(Encoder, Int32, EncoderParameterValueType, IntPtr) EncoderParameter(Encoder, Int32, EncoderParameterValueType, IntPtr) EncoderParameter(Encoder, Int32, EncoderParameterValueType, IntPtr) EncoderParameter(Encoder, Int32, EncoderParameterValueType, IntPtr)

使用指定的 EncoderParameter 物件、值的數目、值的資料型別和儲存在 Encoder 物件中值的指標,初始化 EncoderParameter 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object, number of values, data type of the values, and a pointer to the values stored in the EncoderParameter object.

EncoderParameter(Encoder, Int32, Int32) EncoderParameter(Encoder, Int32, Int32) EncoderParameter(Encoder, Int32, Int32) EncoderParameter(Encoder, Int32, Int32)

使用指定的 EncoderParameter 物件和 32 位元整數的配對,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and a pair of 32-bit integers. 整數的配對表示分數,第一個整數為分子,第二個整數為分母。The pair of integers represents a fraction, the first integer being the numerator, and the second integer being the denominator. 設定 ValueType 屬性為 ValueTypeRational,並設定 NumberOfValues 屬性為 1。Sets the ValueType property to ValueTypeRational, and sets the NumberOfValues property to 1.

EncoderParameter(Encoder, Int32, Int32, Int32) EncoderParameter(Encoder, Int32, Int32, Int32) EncoderParameter(Encoder, Int32, Int32, Int32) EncoderParameter(Encoder, Int32, Int32, Int32)

使用指定的 EncoderParameter 物件和三個整數 (其指定值的數目、值的資料型別和儲存在 Encoder 物件中值的指標),初始化 EncoderParameter 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and three integers that specify the number of values, the data type of the values, and a pointer to the values stored in the EncoderParameter object.

EncoderParameter(Encoder, Int32, Int32, Int32, Int32) EncoderParameter(Encoder, Int32, Int32, Int32, Int32) EncoderParameter(Encoder, Int32, Int32, Int32, Int32) EncoderParameter(Encoder, Int32, Int32, Int32, Int32)

使用指定的 EncoderParameter 物件和四個 32 位元整數,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and four, 32-bit integers. 四個整數表示分數的範圍。The four integers represent a range of fractions. 前兩個整數表示範圍中的最小分數,其餘的兩個整數表示範圍中的最大分數。The first two integers represent the smallest fraction in the range, and the remaining two integers represent the largest fraction in the range. 設定 ValueType 屬性為 ValueTypeRationalRange,並設定 NumberOfValues 屬性為 1。Sets the ValueType property to ValueTypeRationalRange, and sets the NumberOfValues property to 1.

EncoderParameter(Encoder, Int32[], Int32[]) EncoderParameter(Encoder, Int32[], Int32[]) EncoderParameter(Encoder, Int32[], Int32[]) EncoderParameter(Encoder, Int32[], Int32[])

使用指定的 EncoderParameter 物件和兩個 32 位元整數的陣列,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and two arrays of 32-bit integers. 這兩個陣列表示分數的陣列。The two arrays represent an array of fractions. 設定 ValueType 屬性為 ValueTypeRational,並設定 NumberOfValues 屬性為 numerator 陣列中的元素數目,這個數目必須和 denominator 陣列中的元素數目相同。Sets the ValueType property to ValueTypeRational, and sets the NumberOfValues property to the number of elements in the numerator array, which must be the same as the number of elements in the denominator array.

EncoderParameter(Encoder, Int32[], Int32[], Int32[], Int32[]) EncoderParameter(Encoder, Int32[], Int32[], Int32[], Int32[]) EncoderParameter(Encoder, Int32[], Int32[], Int32[], Int32[]) EncoderParameter(Encoder, Int32[], Int32[], Int32[], Int32[])

使用指定的 EncoderParameter 物件和四個 32 位元整數的陣列,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and four arrays of 32-bit integers. 四個陣列表示陣列有理數範圍。The four arrays represent an array rational ranges. 有理數範圍是從最小分數值到最大分數值的所有分數集合。A rational range is the set of all fractions from a minimum fractional value through a maximum fractional value. 設定 ValueType 屬性為 ValueTypeRationalRange,並設定 NumberOfValues 屬性為 numerator1 陣列中的元素數目,這個數目必須與其他三個陣列中的元素數目相同。Sets the ValueType property to ValueTypeRationalRange, and sets the NumberOfValues property to the number of elements in the numerator1 array, which must be the same as the number of elements in the other three arrays.

EncoderParameter(Encoder, Int64) EncoderParameter(Encoder, Int64) EncoderParameter(Encoder, Int64) EncoderParameter(Encoder, Int64)

使用指定的 EncoderParameter 物件和一個 64 位元整數,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and one 64-bit integer. 設定 ValueType 屬性為 ValueTypeLong (32 位元),並設定 NumberOfValues 屬性為 1。Sets the ValueType property to ValueTypeLong (32 bits), and sets the NumberOfValues property to 1.

EncoderParameter(Encoder, Int64, Int64) EncoderParameter(Encoder, Int64, Int64) EncoderParameter(Encoder, Int64, Int64) EncoderParameter(Encoder, Int64, Int64)

使用指定的 Encoder 物件和一組 64 位元整數,初始化 EncoderParameter 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and a pair of 64-bit integers. 整數的配對表示整數的範圍,第一個整數為範圍中的最小數字,第二個整數為範圍中的最大數字。The pair of integers represents a range of integers, the first integer being the smallest number in the range, and the second integer being the largest number in the range. 設定 ValueType 屬性為 ValueTypeLongRange,並設定 NumberOfValues 屬性為 1。Sets the ValueType property to ValueTypeLongRange, and sets the NumberOfValues property to 1.

EncoderParameter(Encoder, Int64[]) EncoderParameter(Encoder, Int64[]) EncoderParameter(Encoder, Int64[]) EncoderParameter(Encoder, Int64[])

使用指定的 Encoder 物件和 64 位元整數的陣列,初始化 EncoderParameter 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and an array of 64-bit integers. 設定 ValueType 屬性為 ValueTypeLong (32 位元),並設定 NumberOfValues 屬性為陣列中的元素數目。Sets the ValueType property to ValueTypeLong (32-bit), and sets the NumberOfValues property to the number of elements in the array.

EncoderParameter(Encoder, Int64[], Int64[]) EncoderParameter(Encoder, Int64[], Int64[]) EncoderParameter(Encoder, Int64[], Int64[]) EncoderParameter(Encoder, Int64[], Int64[])

使用指定的 Encoder 物件和兩個 64 位元整數的陣列,初始化 EncoderParameter 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and two arrays of 64-bit integers. 這兩個陣列表示陣列整數範圍。The two arrays represent an array integer ranges. 設定 ValueType 屬性為 ValueTypeLongRange,並設定 NumberOfValues 屬性為 rangebegin 陣列中的元素數目,這個數目必須和 rangeend 陣列中的元素數目相同。Sets the ValueType property to ValueTypeLongRange, and sets the NumberOfValues property to the number of elements in the rangebegin array, which must be the same as the number of elements in the rangeend array.

EncoderParameter(Encoder, String) EncoderParameter(Encoder, String) EncoderParameter(Encoder, String) EncoderParameter(Encoder, String)

使用指定 EncoderParameter 物件和字元字串,初始化 Encoder 類別的新執行個體。Initializes a new instance of the EncoderParameter class with the specified Encoder object and a character string. 在字串儲存在 EncoderParameter 物件中之前,會先轉換為 Null 終端 ASCII 字串。The string is converted to a null-terminated ASCII string before it is stored in the EncoderParameter object. 設定 ValueType 屬性為 ValueTypeAscii,並設定 NumberOfValues 屬性為包含 null 結束字元 (Terminator) 的 ASCII 字串的長度。Sets the ValueType property to ValueTypeAscii, and sets the NumberOfValues property to the length of the ASCII string including the NULL terminator.

屬性

Encoder Encoder Encoder Encoder

取得或設定與這個 Encoder 物件相關聯的 EncoderParameter 物件。Gets or sets the Encoder object associated with this EncoderParameter object. Encoder 物件會封裝全域唯一識別項 (GUID),其指定儲存在這個 Quality 物件中之參數的分類 (例如 ColorDepthCompressionEncoderParameter)。The Encoder object encapsulates the globally unique identifier (GUID) that specifies the category (for example Quality, ColorDepth, or Compression) of the parameter stored in this EncoderParameter object.

NumberOfValues NumberOfValues NumberOfValues NumberOfValues

取得儲存在這個 EncoderParameter 物件中的值陣列之元素數目。Gets the number of elements in the array of values stored in this EncoderParameter object.

Type Type Type Type

取得儲存在這個 EncoderParameter 物件中的值之資料型別。Gets the data type of the values stored in this EncoderParameter object.

ValueType ValueType ValueType ValueType

取得儲存在這個 EncoderParameter 物件中的值之資料型別。Gets the data type of the values stored in this EncoderParameter object.

方法

Dispose() Dispose() Dispose() Dispose()

釋放這個 EncoderParameter 物件使用的所有資源。Releases all resources used by this EncoderParameter object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

允許 EncoderParameter 物件嘗試釋放資源,並執行其他清除作業,不必等到記憶體回收收回 EncoderParameter 物件。Allows an EncoderParameter object to attempt to free resources and perform other cleanup operations before the EncoderParameter object is reclaimed by garbage collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱