ImageAttributes.SetColorKeyとは? わかりやすく解説

ImageAttributes.SetColorKey メソッド (Color, Color)

既定のカテゴリのカラー キーを設定します。

名前空間: System.Drawing.Imaging
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub SetColorKey ( _
    colorLow As Color, _
    colorHigh As Color _
)
Dim instance As ImageAttributes
Dim colorLow As Color
Dim colorHigh As Color

instance.SetColorKey(colorLow, colorHigh)
public void SetColorKey (
    Color colorLow,
    Color colorHigh
)
public:
void SetColorKey (
    Color colorLow, 
    Color colorHigh
)
public void SetColorKey (
    Color colorLow, 
    Color colorHigh
)
public function SetColorKey (
    colorLow : Color, 
    colorHigh : Color
)

パラメータ

colorLow

下位のカラー キー値。

colorHigh

上位のカラー キー値。

戻り値
このメソッドは値を返しません。

解説解説
使用例使用例

コード例については、SetColorKey(Color,Color,ColorAdjustType) メソッドのトピックを参照してください。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ImageAttributes クラス
ImageAttributes メンバ
System.Drawing.Imaging 名前空間

ImageAttributes.SetColorKey メソッド (Color, Color, ColorAdjustType)

指定したカテゴリのカラー キー (透明度の範囲) を設定します。

名前空間: System.Drawing.Imaging
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub SetColorKey ( _
    colorLow As Color, _
    colorHigh As Color, _
    type As ColorAdjustType _
)
Dim instance As ImageAttributes
Dim colorLow As Color
Dim colorHigh As Color
Dim type As ColorAdjustType

instance.SetColorKey(colorLow, colorHigh, type)
public void SetColorKey (
    Color colorLow,
    Color colorHigh,
    ColorAdjustType type
)
public:
void SetColorKey (
    Color colorLow, 
    Color colorHigh, 
    ColorAdjustType type
)
public void SetColorKey (
    Color colorLow, 
    Color colorHigh, 
    ColorAdjustType type
)
public function SetColorKey (
    colorLow : Color, 
    colorHigh : Color, 
    type : ColorAdjustType
)

パラメータ

colorLow

下位のカラー キー値。

colorHigh

上位のカラー キー値。

type

カラー キーを設定する対象のカテゴリを指定する ColorAdjustType の要素。

戻り値
このメソッドは値を返しません。

解説解説

このメソッドは、透明にする色の範囲を指定する上位と下位のカラー キー値を設定します。色の 3 つの要素 (赤、緑、青) が、それぞれ対応する要素の上位と下位のカラー キーの間にある場合、その色は透明になります。

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

既定のカラー調整設定値およびグレースケール調整設定値は、調整設定値が設定されていないすべてのカテゴリに対して適用されます。たとえば、ペン カテゴリの調整設定を一切指定していない場合、ペン カテゴリには既定の設定が適用されます。

特定のカテゴリに対してカラー調整設定値またはグレースケール調整設定値を指定すると、そのカテゴリに適用されていた既定の調整設定値は解除されます。たとえば、既定のカテゴリに対して調整設定値のコレクションを指定するとします。Pen を SetColorKey メソッドに渡してペン カテゴリのカラー キーを設定すると、ペンには既定の調整設定は一切適用されません。

使用例使用例

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。

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

  2. ImageAttributes オブジェクトを作成し、SetColorKey メソッドを呼び出すことにより、そのオブジェクトのカラー キーを設定します。

  3. ImageAttributes オブジェクトのカラー キーを使用して、イメージを画面に描画します。

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
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);      
    
}
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.get_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.get_Graphics().DrawImage(myImage, rect, 0, 0, 100, 100,
        GraphicsUnit.Pixel, imageAttr);
} //SetColorKeyExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ImageAttributes クラス
ImageAttributes メンバ
System.Drawing.Imaging 名前空間

ImageAttributes.SetColorKey メソッド

カラー キー (透明度の範囲) を設定します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
ImageAttributes.SetColorKey (Color, Color) 既定のカテゴリのカラー キーを設定します。

.NET Compact Framework によってサポートされています。

ImageAttributes.SetColorKey (Color, Color, ColorAdjustType) 指定したカテゴリのカラー キー (透明度の範囲) を設定します。
参照参照

関連項目

ImageAttributes クラス
ImageAttributes メンバ
System.Drawing.Imaging 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ImageAttributes.SetColorKey」の関連用語

ImageAttributes.SetColorKeyのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



ImageAttributes.SetColorKeyのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS