ImageAttributes.SetGamma 方法

定义

设置伽玛值。

重载

SetGamma(Single)

为默认类别设置伽玛值。

SetGamma(Single, ColorAdjustType)

为指定类别设置伽玛值。

SetGamma(Single)

Source:
ImageAttributes.cs
Source:
ImageAttributes.cs
Source:
ImageAttributes.cs

为默认类别设置伽玛值。

public:
 void SetGamma(float gamma);
public void SetGamma (float gamma);
member this.SetGamma : single -> unit
Public Sub SetGamma (gamma As Single)

参数

gamma
Single

灰度校正值。

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此外,需要将映像文件路径更改为系统上有效的路径和映像名称。 此代码执行以下操作:

  1. 打开使用 Image 文件 Camera.jpg 的 ,并使用 gamma 的默认值将其绘制到屏幕。

  2. 创建 一个 ImageAttributes 对象,并通过调用 SetGamma 方法将其伽玛设置为 2.2。

  3. 使用对象中刚刚设置 ImageAttributes 的伽玛值,将图像 (第二个相机) 到屏幕。

private:
   void SetGammaExample( PaintEventArgs^ e )
   {
      // Create an Image object from the file Camera.jpg, and draw it to
      // the screen.
      Image^ myImage = Image::FromFile( "Camera.jpg" );
      e->Graphics->DrawImage( myImage, 20, 20 );

      // Create an ImageAttributes object and set the gamma to 2.2.
      System::Drawing::Imaging::ImageAttributes^ imageAttr = 
          gcnew System::Drawing::Imaging::ImageAttributes;
      imageAttr->SetGamma( 2.2f );

      // Draw the image with gamma set to 2.2.
      Rectangle rect = Rectangle(250,20,200,200);
      e->Graphics->DrawImage( myImage, rect, 0, 0, 200, 200, GraphicsUnit::Pixel, imageAttr );
   }
private void SetGammaExample(PaintEventArgs e)
{
             
    // Create an Image object from the file Camera.jpg, and draw it to
    // the screen.
    Image myImage = Image.FromFile("Camera.jpg");
    e.Graphics.DrawImage(myImage, 20, 20);
             
    // Create an ImageAttributes object and set the gamma to 2.2.
    System.Drawing.Imaging.ImageAttributes imageAttr = 
           new System.Drawing.Imaging.ImageAttributes();
    imageAttr.SetGamma(2.2f);
             
    // Draw the image with gamma set to 2.2.
    Rectangle rect = new Rectangle(250, 20, 200, 200);
    e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200, 
        GraphicsUnit.Pixel, imageAttr);    
}
Public Sub SetGammaExample(ByVal e As PaintEventArgs)

    ' Create an Image object from the file Camera.jpg, and draw

    ' it to screen.
    Dim myImage As Image = Image.FromFile("Camera.jpg")
    e.Graphics.DrawImage(myImage, 20, 20)

    ' Create an ImageAttributes object and set the gamma to 2.2.
    Dim imageAttr As New System.Drawing.Imaging.ImageAttributes
    imageAttr.SetGamma(2.2F)

    ' Draw the image with gamma set to 2.2.
    Dim rect As New Rectangle(250, 20, 200, 200)
    e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200, _
    GraphicsUnit.Pixel, imageAttr)
    ' Image
End Sub

注解

参数的典型值为 gamma 1.0 到 2.2;但是,0.1 到 5.0 的值在某些情况下可能很有用。

对象维护五个 ImageAttributes 调整类别的颜色和灰度设置:默认值、位图、画笔、笔和文本。 例如,可以为默认类别指定伽玛值,为位图类别指定不同的伽玛值,并为笔类别指定不同的伽玛值。

默认颜色调整和灰度调整设置适用于没有自己调整设置的所有类别。 例如,如果从未为笔类别指定任何调整设置,默认设置将应用于笔类别。

超出通常范围的伽玛值对于旧的 CRT 监视器或处于异常照明条件(如工业环境或窗口显示器)的监视器可能很有用。

适用于

SetGamma(Single, ColorAdjustType)

Source:
ImageAttributes.cs
Source:
ImageAttributes.cs
Source:
ImageAttributes.cs

为指定类别设置伽玛值。

public:
 void SetGamma(float gamma, System::Drawing::Imaging::ColorAdjustType type);
public void SetGamma (float gamma, System.Drawing.Imaging.ColorAdjustType type);
member this.SetGamma : single * System.Drawing.Imaging.ColorAdjustType -> unit
Public Sub SetGamma (gamma As Single, type As ColorAdjustType)

参数

gamma
Single

灰度校正值。

type
ColorAdjustType

ColorAdjustType 枚举的一个元素,指定将设置伽玛值的类别。

示例

有关代码示例,请参阅 SetGamma(Single) 方法。

注解

参数的典型值为 gamma 1.0 到 2.2;但是,0.1 到 5.0 的值在某些情况下可能很有用。

对象维护五个 ImageAttributes 调整类别的颜色和灰度设置:默认值、位图、画笔、笔和文本。 例如,可以为默认类别指定伽玛值,为位图类别指定不同的伽玛值,并为笔类别指定不同的伽玛值。

默认颜色调整和灰度调整设置适用于没有自己调整设置的所有类别。 例如,如果从未为笔类别指定任何调整设置,默认设置将应用于笔类别。

为特定类别指定颜色调整或灰度调整设置后,默认调整设置将不再应用于该类别。 例如,假设为默认类别指定调整设置的集合。 如果通过传递给 PenSetGamma 方法设置笔类别的伽玛值,则任何默认调整设置都不会应用于笔。

超出通常范围的伽玛值对于旧的 CRT 监视器或处于异常照明条件(如工业环境或窗口显示器)的监视器可能很有用。

适用于