ImageAttributes.SetGamma 方法

定义

设置伽玛值。Sets the gamma value.

重载

SetGamma(Single)

为默认类别设置伽玛值。Sets the gamma value for the default category.

SetGamma(Single, ColorAdjustType)

为指定类别设置伽玛值。Sets the gamma value for a specified category.

SetGamma(Single)

为默认类别设置伽玛值。Sets the gamma value for the default category.

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

参数

gamma
Single

灰度校正值。The gamma correction value.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要 PaintEventArgse,它是 Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此外,还需要将图像文件路径更改为在系统中有效的路径和映像名称。In addition, you need to change the image file path to a path and image name valid on your system. 此代码执行以下操作:The code performs the following actions:

  1. 打开一个使用文件摄像的 Image,并使用伽玛的默认值将其绘制到屏幕。Opens an Image that uses the file Camera.jpg and draws it to the screen using the default value for gamma.

  2. 创建 ImageAttributes 对象,并通过调用 SetGamma 方法将其伽玛设置为2.2。Creates an ImageAttributes object and sets its gamma to 2.2 by calling the SetGamma method.

  3. 使用刚才在 ImageAttributes 对象中设置的伽玛值将图像(第二个照相机)绘制到屏幕。Draws the image (a second camera) to the screen using the gamma value just set in the ImageAttributes object.

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 的值在某些情况下可能非常有用。Typical values for the gamma parameter are from 1.0 to 2.2; however, values from 0.1 to 5.0 could prove useful in some circumstances.

ImageAttributes 对象维护五个调整类别的颜色和灰度设置:默认值、位图、画笔、笔和文本。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如,可以为默认类别指定一个伽玛值,为位图类别指定一个不同的伽玛值,并为钢笔类别指定一个伽玛值。For example, you can specify a gamma value for the default category, a different gamma value for the bitmap category, and still a different gamma value for the pen category.

默认颜色调整和灰度调整设置适用于没有自己的调整设置的所有类别。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如,如果您从未为 "笔" 类别指定任何调整设置,则默认设置将应用于 "笔" 类别。For example, if you never specify any adjustment settings for the pen category, the default settings apply to the pen category.

对于旧的 CRT 监视器,或在非正常照明条件下的监视器(如工业环境或窗口显示)中,伽玛值可能非常有用。Gamma values outside the usual range may be useful for old CRT monitors or for monitors that are in unusual lighting conditions, such as industrial environments or window displays.

SetGamma(Single, ColorAdjustType)

为指定类别设置伽玛值。Sets the gamma value for a specified category.

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

灰度校正值。The gamma correction value.

type
ColorAdjustType

ColorAdjustType 枚举的一个元素,指定将设置伽玛值的类别。An element of the ColorAdjustType enumeration that specifies the category for which the gamma value is set.

示例

有关代码示例,请参阅 SetGamma(Single) 方法。For a code example, see the SetGamma(Single) method.

注解

gamma 参数的典型值是从1.0 到 2.2;但是,从0.1 到5.0 的值在某些情况下可能非常有用。Typical values for the gamma parameter are from 1.0 to 2.2; however, values from 0.1 to 5.0 could prove useful in some circumstances.

ImageAttributes 对象维护五个调整类别的颜色和灰度设置:默认值、位图、画笔、笔和文本。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如,可以为默认类别指定一个伽玛值,为位图类别指定一个不同的伽玛值,并为钢笔类别指定一个伽玛值。For example, you can specify a gamma value for the default category, a different gamma value for the bitmap category, and still a different gamma value for the pen category.

默认颜色调整和灰度调整设置适用于没有自己的调整设置的所有类别。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如,如果您从未为 "笔" 类别指定任何调整设置,则默认设置将应用于 "笔" 类别。For example, if you never specify any adjustment settings for the pen category, the default settings apply to the pen category.

为某个类别指定颜色调整或灰度调整设置后,默认调整设置将不再应用于该类别。As soon as you specify a color-adjustment or grayscale-adjustment setting for a certain category, the default adjustment settings no longer apply to that category. 例如,假设您为默认类别指定了调整设置的集合。For example, suppose you specify a collection of adjustment settings for the default category. 如果通过将 Pen 传递到 SetGamma 方法来设置笔类别的伽玛值,则没有任何默认调整设置将应用于钢笔。If you set the gamma value for the pen category by passing Pen to the SetGamma method, none of the default adjustment settings will apply to pens.

对于旧的 CRT 监视器,或在非正常照明条件下的监视器(如工业环境或窗口显示)中,伽玛值可能非常有用。Gamma values outside the usual range may be useful for old CRT monitors or for monitors that are in unusual lighting conditions, such as industrial environments or window displays.

适用于