Share via


カラー再マッピング テーブルの使用

再マップとは、カラー リマップ テーブルにしたがって画像の色を変換する処理のことです。 カラー 再マップ テーブルは、 ColorMap 構造体の配列です。 配列内の各 ColorMap 構造体には、 oldColor メンバーと newColor メンバーがあります。

GDI+ によって画像が描画されるときに、画像の各ピクセルは古い色の配列と比較されます。 ピクセルの色が古い色と一致した場合、その色は対応する新しい色に変更されます。 色はレンダリングでのみ変更されます。イメージ自体 ( Image オブジェクトまたは Bitmap オブジェクトに格納されている) の色値は変更されません。

再マップされたイメージを描画するには、 ColorMap 構造体の配列を初期化します。 その配列のアドレスを ImageAttributes オブジェクトの ImageAttributes::SetRemapTable メソッドに渡し、ImageAttributes オブジェクトのアドレスGraphics オブジェクトの DrawImage Methods メソッドに渡します。

次の例では、ファイル RemapInput.bmpから Image オブジェクトを作成します。 このコードでは、1 つの ColorMap 構造体で構成されるカラー 再マップ テーブルを作成します。 ColorMap 構造体の oldColor メンバーは赤で、newColor メンバーは青です。 画像は再マップなしで 1 回、再マップありで 1 回描画されます。 再マップ プロセスにより、すべての赤色のピクセルが青色に変更されます。

Image            image(L"RemapInput.bmp");
ImageAttributes  imageAttributes;
UINT             width = image.GetWidth();
UINT             height = image.GetHeight();
ColorMap         colorMap[1];

colorMap[0].oldColor = Color(255, 255, 0, 0);  // opaque red
colorMap[0].newColor = Color(255, 0, 0, 255);  // opaque blue

imageAttributes.SetRemapTable(1, colorMap, ColorAdjustTypeBitmap);

graphics.DrawImage(&image, 10, 10, width, height);

graphics.DrawImage(
   &image, 
   Rect(150, 10, width, height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle 
   width,       // width of source rectangle
   height,      // height of source rectangle
   UnitPixel,
   &imageAttributes);

次の図は、左側に元の画像、右側に再マップ後の画像を示したものです。

多色の画像の 2 つのバージョンを示す図。最初のバージョンの赤い領域は、2 番目のバージョンでは青です