ImageAttributes.SetColorKey メソッド (Color, Color)
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As ImageAttributes Dim colorLow As Color Dim colorHigh As Color instance.SetColorKey(colorLow, colorHigh)
戻り値
このメソッドは値を返しません。

このメソッドは、透明にする色の範囲を指定する上位と下位のカラー キー値を設定します。色の 3 つの要素 (赤、緑、青) が、それぞれ対応する要素の上位と下位のカラー キーの間にある場合、その色は透明になります。
ImageAttributes オブジェクトは、5 つの調整カテゴリ (既定、ビットマップ、ブラシ、ペン、テキスト) に関して色とグレースケールの設定を保持します。たとえば、既定のカテゴリに対してあるカラー キーを指定し、ビットマップ カテゴリには別のカラー キーを指定し、さらにペン カテゴリにも異なるカラー キーを指定できます。
既定のカラー調整設定値およびグレースケール調整設定値は、調整設定値が設定されていないすべてのカテゴリに対して適用されます。たとえば、ペン カテゴリの調整設定を一切指定していない場合、ペン カテゴリには既定の設定が適用されます。


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ImageAttributes.SetColorKey メソッド (Color, Color, ColorAdjustType)
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As ImageAttributes Dim colorLow As Color Dim colorHigh As Color Dim type As ColorAdjustType instance.SetColorKey(colorLow, colorHigh, type)
戻り値
このメソッドは値を返しません。

このメソッドは、透明にする色の範囲を指定する上位と下位のカラー キー値を設定します。色の 3 つの要素 (赤、緑、青) が、それぞれ対応する要素の上位と下位のカラー キーの間にある場合、その色は透明になります。
ImageAttributes オブジェクトは、5 つの調整カテゴリ (既定、ビットマップ、ブラシ、ペン、テキスト) に関して色とグレースケールの設定を保持します。たとえば、既定のカテゴリに対してあるカラー キーを指定し、ビットマップ カテゴリには別のカラー キーを指定し、さらにペン カテゴリにも異なるカラー キーを指定できます。
既定のカラー調整設定値およびグレースケール調整設定値は、調整設定値が設定されていないすべてのカテゴリに対して適用されます。たとえば、ペン カテゴリの調整設定を一切指定していない場合、ペン カテゴリには既定の設定が適用されます。
特定のカテゴリに対してカラー調整設定値またはグレースケール調整設定値を指定すると、そのカテゴリに適用されていた既定の調整設定値は解除されます。たとえば、既定のカテゴリに対して調整設定値のコレクションを指定するとします。Pen を SetColorKey メソッドに渡してペン カテゴリのカラー キーを設定すると、ペンには既定の調整設定は一切適用されません。

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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ImageAttributes.SetColorKey メソッド
- ImageAttributes.SetColorKey メソッドのページへのリンク