语言

ImageAttributes.SetColorKey 方法

定义

设置颜色键(透明度范围)。

重载

名称 说明
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
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 -> unit
Public Sub SetColorKey (colorLow As Color, colorHigh As Color, type As ColorAdjustType)

参数

colorLow
Color

低颜色键值。

colorHigh
Color

高颜色键值。

type
ColorAdjustType

一个元素 ColorAdjustType ,指定为其设置了颜色键的类别。

示例

下面的代码示例设计用于 Windows 窗体,它需要 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)

Source:
ImageAttributes.cs
Source:
ImageAttributes.cs
Source:
ImageAttributes.cs
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 -> unit
Public Sub SetColorKey (colorLow As Color, colorHigh As Color)

参数

colorLow
Color

低颜色键值。

colorHigh
Color

高颜色键值。

示例

有关代码示例,请参阅该方法 SetColorKey(Color, Color, ColorAdjustType) 。

注解

此方法设置高低颜色键值,以便使一系列颜色透明。 具有其三个分量(红色、绿色、蓝色)之间的相应颜色(红色、绿色、蓝色)之间的任何颜色都透明。

对象维护五个 ImageAttributes 调整类别的颜色和灰度设置:默认、位图、画笔、笔和文本。 例如,可以为默认类别指定颜色键、位图类别的不同颜色键,以及笔类别的颜色键不同。

默认颜色调整和灰度调整设置适用于没有自己调整设置的所有类别。 例如,如果从未为笔类别指定任何调整设置,则默认设置将应用于笔类别。

适用于