Bagikan melalui


EncoderParameters Konstruktor

Definisi

Menginisialisasi instans EncoderParameters baru kelas yang dapat berisi jumlah EncoderParameter objek yang ditentukan.

Overload

EncoderParameters()

Menginisialisasi instans EncoderParameters baru kelas yang dapat berisi satu EncoderParameter objek.

EncoderParameters(Int32)

Menginisialisasi instans EncoderParameters baru kelas yang dapat berisi jumlah EncoderParameter objek yang ditentukan.

EncoderParameters()

Sumber:
EncoderParameters.cs
Sumber:
EncoderParameters.cs
Sumber:
EncoderParameters.cs

Menginisialisasi instans EncoderParameters baru kelas yang dapat berisi satu EncoderParameter objek.

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

Contoh

Contoh kode berikut menunjukkan cara membuat dan menggunakan EncoderParameters objek. Untuk menjalankan contoh ini, tempelkan kode ke dalam Formulir Windows dan panggil VaryQualityLevel metode dari konstruktor formulir. Contoh ini memerlukan file gambar bernama TestPhoto.jpg yang terletak di 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

Keterangan

Save Beberapa metode dan SaveAdd menerima EncoderParameters objek sebagai argumen. Metode GetEncoderParameterList mengembalikan EncoderParameters objek.

Berlaku untuk

EncoderParameters(Int32)

Sumber:
EncoderParameters.cs
Sumber:
EncoderParameters.cs
Sumber:
EncoderParameters.cs

Menginisialisasi instans EncoderParameters baru kelas yang dapat berisi jumlah EncoderParameter objek yang ditentukan.

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

Parameter

count
Int32

Bilangan bulat yang menentukan jumlah EncoderParameter objek yang dapat dimuat EncoderParameters objek.

Berlaku untuk