ImageAttributes::SetColorKey メソッド (gdiplusimageattributes.h)

ImageAttributes::SetColorKey メソッドは、指定したカテゴリのカラー キー (透明度の範囲) を設定します。

構文

Status SetColorKey(
  [in, ref]      const Color &   colorLow,
  [in, ref]      const Color &   colorHigh,
  [in, optional] ColorAdjustType type
);

パラメーター

[in, ref] colorLow

種類: const Color

低い色キー値を指定する Color オブジェクトへの参照。

[in, ref] colorHigh

種類: const Color

高いカラー キー値を指定する Color オブジェクトへの参照。

[in, optional] type

種類: ColorAdjustType

カラー キーが設定されるカテゴリを指定する ColorAdjustType 列挙体の要素。 既定値は ColorAdjustTypeDefault です

戻り値

種類: 状態

メソッドが成功した場合は、Status 列挙の要素である Ok を返します

メソッドが失敗した場合は、 Status 列挙体の他の要素のいずれかを返します。

注釈

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

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

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

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

次の例では、.bmp ファイルから Image オブジェクトを作成します。 このコードでは、 ImageAttributes オブジェクトも作成されます。 ImageAttributes::SetColorKey を呼び出すと、ImageAttributes オブジェクトのビットマップ カラー キーが設定され、次の 3 つの条件をすべて満たす色が透明になります。

  • 赤色の成分は、100 ~ 250 の範囲です。
  • 緑色のコンポーネントの範囲は 95 から 245 です。
  • 青色の成分は、30 ~ 60 の範囲です。

VOID Example_SetColorKey(HDC hdc)
{
   Graphics graphics(hdc);

   // Create an Image object based on a BMP file.
   // The image has three horizontal stripes.
   // The color of the top stripe has RGB components (90, 90, 20).
   // The color of the middle stripe has RGB components (150, 150, 150).
   // The color of the bottom stripe has RGB components (130, 130, 40).
   Image image(L"ColorKeyTest.bmp");

   // Create an ImageAttributes object, and set its color key.
   ImageAttributes imAtt;
   imAtt.SetColorKey(
      Color(100, 95, 30),
      Color(250, 245, 60),
      ColorAdjustTypeBitmap);

   // Draw the image. Apply the color key.
   // The bottom stripe of the image will be transparent because
   // 100 <= 130 <= 250 and
   // 95  <= 130 <= 245 and
   // 30  <= 40  <= 60.
   graphics.DrawImage(
      &image, 
      Rect(20, 20, image.GetWidth(), image.GetHeight()),  // dest rect
      0, 0, image.GetWidth(), image.GetHeight(),          // source rect
      UnitPixel,
      &imAtt);
}
				

要件

要件
サポートされている最小のクライアント Windows XP、Windows 2000 Professional [デスクトップ アプリのみ]
サポートされている最小のサーバー Windows 2000 Server [デスクトップ アプリのみ]
対象プラットフォーム Windows
ヘッダー gdiplusimageattributes.h (Gdiplus.h を含む)
Library Gdiplus.lib
[DLL] Gdiplus.dll

こちらもご覧ください

Bitmap

Color

ColorAdjustType

Image

ImageAttributes

ImageAttributes::ClearColorKey

ImageAttributes::ClearThreshold

ImageAttributes::SetThreshold

メタファイル

色変更