ImageAttributes.SetGamma 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定伽瑪值。
多載
| 名稱 | Description |
|---|---|
| SetGamma(Single) |
設定預設類別的伽瑪值。 |
| SetGamma(Single, ColorAdjustType) |
設定特定類別的伽瑪值。 |
SetGamma(Single)
設定預設類別的伽瑪值。
public:
void SetGamma(float gamma);
public void SetGamma(float gamma);
member this.SetGamma : single -> unit
Public Sub SetGamma (gamma As Single)
參數
- gamma
- Single
伽瑪校正值。
範例
以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 此外,你需要將影像檔案路徑改成系統上有效的路徑和影像名稱。 此程式碼會執行下列動作:
打開 Image 一個使用檔案 Camera.jpg,並用預設值的伽瑪值繪製到螢幕上。
建立一個 ImageAttributes 物件,並透過呼叫 SetGamma 方法將其 gamma 設為 2.2。
利用物件中剛設定 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 會維持五個調整類別的色彩與灰階設定:預設、點陣圖、筆刷、筆觸和文字。 例如,你可以為預設類別指定 gamma 值,為點陣分類指定不同的 gamma 值,筆型類別則有不同的 gamma 值。
默認色彩調整和灰階調整設定適用於沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。
超出一般範圍的伽瑪值對於舊式CRT顯示器或處於特殊光線條件(如工業環境或窗簾)的顯示器可能有用。
適用於
SetGamma(Single, ColorAdjustType)
設定特定類別的伽瑪值。
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 會維持五個調整類別的色彩與灰階設定:預設、點陣圖、筆刷、筆觸和文字。 例如,你可以為預設類別指定 gamma 值,為點陣分類指定不同的 gamma 值,筆型類別則有不同的 gamma 值。
默認色彩調整和灰階調整設定適用於沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。
一旦您指定特定類別的色彩調整或灰階調整設定,預設調整設定就不再套用至該類別。 例如,假設您指定預設類別的調整設定集合。 如果你透過傳入PenSetGamma方法設定筆類別的伽瑪值,預設的調整設定就不會套用在筆上。
超出一般範圍的伽瑪值對於舊式CRT顯示器或處於特殊光線條件(如工業環境或窗簾)的顯示器可能有用。