Language

ImageAttributes.SetColorKey メソッド

定義

カラー キー (透明度の範囲) を設定します。

オーバーロード

名前 説明
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 フォームで使用するように設計されており、PaintEventArgse が必要です。これは、Paint イベント ハンドラーのパラメーターです。 コードは次のアクションを実行します。

  1. ファイル Circle.bmp を使用する Image を開き、画面に描画します。

  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

注釈

このメソッドは、色の範囲を透明にできるように、高および低の色キー値を設定します。 ハイ カラー キーとロー カラー キーの対応するコンポーネントの間に 3 つのコンポーネント (赤、緑、青) のそれぞれを持つ任意の色が透明になります。

ImageAttributes オブジェクトは、既定、ビットマップ、ブラシ、ペン、テキストの 5 つの調整カテゴリの色とグレースケールの設定を維持します。 たとえば、既定のカテゴリの色キー、ビットマップ カテゴリに別の色キー、ペン カテゴリに対して別の色キーを指定できます。

既定の色調整とグレースケール調整の設定は、独自の調整設定を持たないすべてのカテゴリに適用されます。 たとえば、ペン カテゴリの調整設定を指定しない場合、既定の設定はペン カテゴリに適用されます。

特定のカテゴリに対して色調整またはグレースケール調整設定を指定するとすぐに、既定の調整設定がそのカテゴリに適用されなくなります。 たとえば、既定のカテゴリの調整設定のコレクションを指定するとします。 Pen メソッドにSetColorKeyを渡してペン カテゴリのカラー キーを設定した場合、既定の調整設定はペンに適用されなくなります。

適用対象

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) メソッドを参照してください。

注釈

このメソッドは、色の範囲を透明にできるように、高および低の色キー値を設定します。 ハイ カラー キーとロー カラー キーの対応するコンポーネントの間に 3 つのコンポーネント (赤、緑、青) のそれぞれを持つ任意の色が透明になります。

ImageAttributes オブジェクトは、既定、ビットマップ、ブラシ、ペン、テキストの 5 つの調整カテゴリの色とグレースケールの設定を維持します。 たとえば、既定のカテゴリの色キー、ビットマップ カテゴリに別の色キー、ペン カテゴリに対して別の色キーを指定できます。

既定の色調整とグレースケール調整の設定は、独自の調整設定を持たないすべてのカテゴリに適用されます。 たとえば、ペン カテゴリの調整設定を指定しない場合、既定の設定はペン カテゴリに適用されます。

適用対象