ImageAttributes.SetGamma 方法

定義

設定 Gamma 值。

多載

SetGamma(Single)

設定預設分類的 Gamma 值。

SetGamma(Single, ColorAdjustType)

設定指定分類的 Gamma 值。

SetGamma(Single)

來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs

設定預設分類的 Gamma 值。

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

參數

gamma
Single

Gamma 修正值。

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse,這是事件處理程序的參數Paint。 此外,您必須將映像檔路徑變更為系統上有效的路徑和映像名稱。 此程式碼會執行下列動作:

  1. 開啟使用檔案 Camera.jpg 的 , Image 並使用 gamma 的預設值將它繪製到畫面。

  2. ImageAttributes建立 物件,並藉由呼叫 SetGamma 方法將其 gamma 設定為 2.2。

  3. 使用剛在 對象中 ImageAttributes 設定的 gamma 值,將影像 (第二個相機) 繪製到畫面。

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 調整類別的色彩和灰階設定:預設、點陣圖、筆刷、手寫筆和文字。 例如,您可以指定預設類別的 gamma 值、位陣圖類別的不同 gamma 值,以及畫筆類別的相同 gamma 值。

默認色彩調整和灰階調整設定會套用至沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。

在一般範圍以外的 Gamma 值對於舊的 CRT 監視器或處於異常光源狀況的監視器可能很有用,例如工業環境或視窗顯示器。

適用於

SetGamma(Single, ColorAdjustType)

來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs

設定指定分類的 Gamma 值。

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 修正值。

type
ColorAdjustType

ColorAdjustType 列舉的元素,指定已經設定 Gamma 值的分類。

範例

如需程式代碼範例,請參閱 SetGamma(Single) 方法。

備註

參數的 gamma 一般值是從 1.0 到 2.2;不過,在某些情況下,0.1 到 5.0 的值可能很有用。

對象會維護五個 ImageAttributes 調整類別的色彩和灰階設定:預設、點陣圖、筆刷、手寫筆和文字。 例如,您可以指定預設類別的 gamma 值、位陣圖類別的不同 gamma 值,以及畫筆類別的相同 gamma 值。

默認色彩調整和灰階調整設定會套用至沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。

一旦您指定特定類別的色彩調整或灰階調整設定,預設調整設定就不再套用至該類別。 例如,假設您指定預設類別的調整設定集合。 如果您傳遞 PenSetGamma 方法來設定畫筆類別的 gamma 值,則預設調整設定都不會套用至畫筆。

在一般範圍以外的 Gamma 值對於舊的 CRT 監視器或處於異常光源狀況的監視器可能很有用,例如工業環境或視窗顯示器。

適用於