ImageAttributes.SetColorKey 方法

定義

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

多載

SetColorKey(Color, Color, ColorAdjustType)

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

SetColorKey(Color, Color)

設定預設分類的色鍵。

SetColorKey(Color, Color, ColorAdjustType)

來源:
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

設定預設分類的色鍵。

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

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

適用於