語言

ImageAttributes.SetColorKey 方法

定義

設定色彩鍵(透明度範圍)。

多載

名稱 Description
SetColorKey(Color, Color, ColorAdjustType)

設定指定類別的色彩鍵(透明度範圍)。

SetColorKey(Color, Color)

設定預設類別的顏色鍵。

SetColorKey(Color, Color, ColorAdjustType)

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

設定指定類別的色彩鍵(透明度範圍)。

public:
 void SetColorKey(System::Drawing::Color colorLow, System::Drawing::Color colorHigh, System::Drawing::Imaging::ColorAdjustType type);
public void SetColorKey(System.Drawing.Color colorLow, System.Drawing.Color colorHigh, System.Drawing.Imaging.ColorAdjustType type);
member this.SetColorKey : System.Drawing.Color * System.Drawing.Color * System.Drawing.Imaging.ColorAdjustType -> unit
Public Sub SetColorKey (colorLow As Color, colorHigh As Color, type As ColorAdjustType)

參數

colorLow
Color

低色彩鍵數值。

colorHigh
Color

高調色標值。

type
ColorAdjustType

其中的一個元素 ColorAdjustType 指定了色彩鍵所設定的類別。

範例

以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 此程式碼會執行下列動作:

  1. 打開 Image 一個使用檔案 Circle.bmp 並繪製到螢幕上的應用程式。

  2. 建立一個 ImageAttributes 物件並透過呼叫 SetColorKey 方法設定其顏色鍵。

  3. 利用物件的 ImageAttributes 色彩鍵將影像繪製到螢幕上。

private:
   void SetColorKeyExample( PaintEventArgs^ e )
   {
      // Open an Image file and draw it to the screen.
      Image^ myImage = Image::FromFile( "Circle.bmp" );
      e->Graphics->DrawImage( myImage, 20, 20 );

      // Create an ImageAttributes object and set the color key.
      Color lowerColor = Color::FromArgb( 245, 0, 0 );
      Color upperColor = Color::FromArgb( 255, 0, 0 );
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetColorKey( lowerColor, upperColor, ColorAdjustType::Default );

      // Draw the image with the color key set.
      Rectangle rect = Rectangle(150,20,100,100);
      e->Graphics->DrawImage( myImage, rect, 0, 0, 100, 100, GraphicsUnit::Pixel, imageAttr );
   }
private void SetColorKeyExample(PaintEventArgs e)
{
             
    // Open an Image file and draw it to the screen.
    Image myImage = Image.FromFile("Circle.bmp");
    e.Graphics.DrawImage(myImage, 20, 20);
             
    // Create an ImageAttributes object and set the color key.
    Color lowerColor = Color.FromArgb(245,0,0);
    Color upperColor = Color.FromArgb(255,0,0);
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetColorKey(lowerColor,
        upperColor,
        ColorAdjustType.Default);
             
    // Draw the image with the color key set.
    Rectangle rect = new Rectangle(150, 20, 100, 100);
    e.Graphics.DrawImage(myImage, rect, 0, 0, 100, 100, 
        GraphicsUnit.Pixel, imageAttr);      
}
Public Sub SetColorKeyExample(ByVal e As PaintEventArgs)

    ' Open an Image file, and draw it to the screen.
    Dim myImage As Image = Image.FromFile("Circle.bmp")
    e.Graphics.DrawImage(myImage, 20, 20)

    ' Create an ImageAttributes object and set the color key.
    Dim lowerColor As Color = Color.FromArgb(245, 0, 0)
    Dim upperColor As Color = Color.FromArgb(255, 0, 0)
    Dim imageAttr As New ImageAttributes
    imageAttr.SetColorKey(lowerColor, upperColor, _
    ColorAdjustType.Default)

    ' Draw the image with the color key set.
    Dim rect As New Rectangle(150, 20, 100, 100)
    e.Graphics.DrawImage(myImage, rect, 0, 0, 100, 100, _
    GraphicsUnit.Pixel, imageAttr)
    ' Image
End Sub

備註

此方法設定高低色彩鍵值,使得色彩範圍能透明。 任何其三個成分(紅、綠、藍)都位於高低色鍵對應分量之間的顏色,皆為透明。

物件 ImageAttributes 會維持五個調整類別的色彩與灰階設定:預設、點陣圖、筆刷、筆觸和文字。 例如,你可以為預設類別指定顏色鍵,為點陣圖類別指定不同的顏色鍵,筆的類別則是不同的顏色鍵。

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

一旦您指定特定類別的色彩調整或灰階調整設定,預設調整設定就不再套用至該類別。 例如,假設您指定預設類別的調整設定集合。 如果你透過傳入PenSetColorKey方法設定筆類別的顏色鍵,筆的預設調整設定就不會套用在筆上。

適用於

SetColorKey(Color, Color)

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

設定預設類別的顏色鍵。

public:
 void SetColorKey(System::Drawing::Color colorLow, System::Drawing::Color colorHigh);
public void SetColorKey(System.Drawing.Color colorLow, System.Drawing.Color colorHigh);
member this.SetColorKey : System.Drawing.Color * System.Drawing.Color -> unit
Public Sub SetColorKey (colorLow As Color, colorHigh As Color)

參數

colorLow
Color

低色彩鍵數值。

colorHigh
Color

高調色標值。

範例

程式碼範例請參見該 SetColorKey(Color, Color, ColorAdjustType) 方法。

備註

此方法設定高低色彩鍵值,使得色彩範圍能透明。 任何其三個成分(紅、綠、藍)都位於高低色鍵對應分量之間的顏色,皆為透明。

物件 ImageAttributes 會維持五個調整類別的色彩與灰階設定:預設、點陣圖、筆刷、筆觸和文字。 例如,你可以為預設類別指定顏色鍵,為點陣圖類別指定不同的顏色鍵,筆的類別則是不同的顏色鍵。

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

適用於