ImageAttributes.SetGamma 方法

定義

設定 Gamma 值。Sets the gamma value.

多載

SetGamma(Single)

設定預設分類的 Gamma 值。Sets the gamma value for the default category.

SetGamma(Single, ColorAdjustType)

設定指定分類的 Gamma 值。Sets the gamma value for a specified category.

SetGamma(Single)

設定預設分類的 Gamma 值。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

Gamma 修正值。The gamma correction value.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計, 而且PaintEventArgs它需要e, 這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. 開啟使用檔案攝影機的,並使用gamma的預設值將它繪製到螢幕上。ImageOpens an Image that uses the file Camera.jpg and draws it to the screen using the default value for gamma.

  2. 建立物件, 並藉由SetGamma呼叫方法, 將其 gamma 設為2.2。 ImageAttributesCreates an ImageAttributes object and sets its gamma to 2.2 by calling the SetGamma method.

  3. 使用剛才在ImageAttributes物件中設定的 gamma 值, 將影像 (第二張相機) 繪製到螢幕上。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. 例如, 您可以指定預設分類的 gamma 值、點陣圖類別目錄的不同 gamma 值, 以及畫筆分類的 gamma 值。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.

一般範圍外的 Gamma 值可能適用于舊式 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)

設定指定分類的 Gamma 值。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

Gamma 修正值。The gamma correction value.

type
ColorAdjustType

ColorAdjustType 列舉的元素,指定已經設定 Gamma 值的分類。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. 例如, 您可以指定預設分類的 gamma 值、點陣圖類別目錄的不同 gamma 值, 以及畫筆分類的 gamma 值。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至方法來設定 [畫筆] 分類的 gamma 值, 則不會將任何預設的調整設定套用到畫筆。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.

一般範圍外的 Gamma 值可能適用于舊式 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.

適用於