ImageAttributes.SetColorKey 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
设置颜色键(透明度范围)。
重载
| SetColorKey(Color, Color, ColorAdjustType) | 设置指定类别的颜色键(透明度范围)。 | 
| SetColorKey(Color, Color) | 设置默认类别的颜色键。 | 
SetColorKey(Color, Color, ColorAdjustType)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- 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 -> unitPublic Sub SetColorKey (colorLow As Color, colorHigh As Color, type As ColorAdjustType)参数
- colorLow
- Color
低颜色键值。
- colorHigh
- Color
高颜色键值。
- type
- ColorAdjustType
一个 ColorAdjustType 元素,指定为其设置颜色键的类别。
示例
下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
- 打开使用文件 Circle.bmp 并将其绘制到屏幕的 Image。 
- 创建一个 ImageAttributes 对象,并通过调用 SetColorKey 方法设置其颜色键。 
- 使用 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 对象维护五个调整类别的颜色和灰度设置:默认、位图、画笔、笔和文本。 例如,可以为默认类别指定颜色键、位图类别的不同颜色键,以及笔类别的颜色键不同。
默认颜色调整和灰度调整设置适用于没有自己调整设置的所有类别。 例如,如果从未为笔类别指定任何调整设置,则默认设置将应用于笔类别。
指定特定类别的颜色调整或灰度调整设置后,默认调整设置将不再应用于该类别。 例如,假设为默认类别指定调整设置的集合。 如果将 Pen 传递给 SetColorKey 方法来设置笔类别的颜色键,则默认调整设置将不适用于笔。
适用于
SetColorKey(Color, Color)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- 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 -> unitPublic Sub SetColorKey (colorLow As Color, colorHigh As Color)参数
- colorLow
- Color
低颜色键值。
- colorHigh
- Color
高颜色键值。
示例
有关代码示例,请参阅 SetColorKey(Color, Color, ColorAdjustType) 方法。
注解
此方法设置高低颜色键值,以便使一系列颜色透明。 具有其三个分量(红色、绿色、蓝色)之间的相应颜色(红色、绿色、蓝色)之间的任何颜色都透明。
ImageAttributes 对象维护五个调整类别的颜色和灰度设置:默认、位图、画笔、笔和文本。 例如,可以为默认类别指定颜色键、位图类别的不同颜色键,以及笔类别的颜色键不同。
默认颜色调整和灰度调整设置适用于没有自己调整设置的所有类别。 例如,如果从未为笔类别指定任何调整设置,则默认设置将应用于笔类别。