カラー キー (透明度の範囲) を設定します。
オーバーロードの一覧
既定のカテゴリのカラー キーを設定します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Sub SetColorKey(Color, Color)
指定したカテゴリのカラー キー (透明度の範囲) を設定します。
[Visual Basic] Overloads Public Sub SetColorKey(Color, Color, ColorAdjustType)
[C#] public void SetColorKey(Color, Color, ColorAdjustType);
[C++] public: void SetColorKey(Color, Color, ColorAdjustType);
[JScript] public function SetColorKey(Color, Color, ColorAdjustType);
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- ファイル Circle.bmp を使用する Image オブジェクトを開き、それを画面に描画します。
- ImageAttributes オブジェクトを作成し、 SetColorKey メソッドを呼び出すことにより、そのオブジェクトのカラー キーを設定します。
- ImageAttributes オブジェクトのカラー キーを使用して、イメージを画面に描画します。
[Visual Basic, C#] メモ ここでは、SetColorKey のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Public Sub SetColorKeyExample(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
[C#]
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, // Image
rect, // Dest. rect.
0, // srcX
0, // srcY
100, // srcWidth
100, // srcHeight
GraphicsUnit.Pixel, // srcUnit
imageAttr); // ImageAttributes
}
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
参照
ImageAttributes クラス | ImageAttributes メンバ | System.Drawing.Imaging 名前空間