EncoderParameters 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化可包含指定数量的 EncoderParameters 对象的 EncoderParameter 类的新实例。
重载
EncoderParameters() |
初始化可包含一个 EncoderParameters 对象的 EncoderParameter 类的新实例。 |
EncoderParameters(Int32) |
初始化可包含指定数量的 EncoderParameters 对象的 EncoderParameter 类的新实例。 |
EncoderParameters()
- Source:
- EncoderParameters.cs
- Source:
- EncoderParameters.cs
- Source:
- EncoderParameters.cs
初始化可包含一个 EncoderParameters 对象的 EncoderParameter 类的新实例。
public:
EncoderParameters();
public EncoderParameters ();
Public Sub New ()
示例
下面的代码示例演示如何创建和使用 EncoderParameters 对象。 若要运行此示例,请将代码粘贴到 Windows 窗体中, VaryQualityLevel
然后从窗体的构造函数调用 方法。 此示例需要位于 c:\处的名为 TestPhoto.jpg
的图像文件。
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
注解
某些 Save 和 SaveAdd 方法接收 EncoderParameters 对象作为参数。 该 GetEncoderParameterList 方法返回 EncoderParameters 对象。
适用于
EncoderParameters(Int32)
- Source:
- EncoderParameters.cs
- Source:
- EncoderParameters.cs
- Source:
- 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 对象的数目。