補間モードを使用してスケーリング中にイメージの品質を制御する

グラフィックス オブジェクトの補間モードは、Windows GDI+ によるイメージの拡大縮小 (拡大と縮小) の方法に影響します。 Gdiplusenums.h の InterpolationMode 列挙では、いくつかの補間モードが定義されています。その一部を次の一覧に示します。

  • InterpolationModeNearestNeighbor
  • InterpolationModeBilinear
  • InterpolationModeHighQualityBilinear
  • InterpolationModeBicubic
  • InterpolationModeHighQualityBicubic

画像を拡大するには、元の画像内の各ピクセルが、拡大された画像内の一連のピクセルにマップされる必要があります。 画像を縮小するには、元の画像内の一連のピクセルが、縮小された画像内の 1 つのピクセルにマップされる必要があります。 拡大縮小後の画像の品質は、これらのマッピングを実行するアルゴリズムの有効性によって左右されます。 拡大画像や縮小画像を高品質に生成するアルゴリズムでは、より多くの処理時間が必要になる傾向があります。 前の一覧では、InterpolationModeNearestNeighbor が最も低品質のモードであり、InterpolationModeHighQualityBicubic が最高品質モードです。

補間モードを設定するには、InterpolationMode 列挙のメンバーの 1 つを Graphics オブジェクトの SetInterpolationMode メソッドに渡します。

次の例では、イメージを描画し、3 つの異なる補間モードでイメージを縮小します。

Image image(L"GrapeBunch.bmp");
UINT width = image.GetWidth();
UINT height = image.GetHeight();
// Draw the image with no shrinking or stretching.
graphics.DrawImage(
   &image,
   Rect(10, 10, width, height),  // destination rectangle  
   0, 0,        // upper-left corner of source rectangle
   width,       // width of source rectangle
   height,      // height of source rectangle
   UnitPixel);
// Shrink the image using low-quality interpolation. 
graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);
graphics.DrawImage(
   &image,
   Rect(10, 250, 0.6*width, 0.6*height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle
   width,       // width of source rectangle
   height,      // height of source rectangle
   UnitPixel);
// Shrink the image using medium-quality interpolation.
graphics.SetInterpolationMode(InterpolationModeHighQualityBilinear);
graphics.DrawImage(
   &image,
   Rect(150, 250, 0.6 * width, 0.6 * height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle
   width,       // width of source rectangle
   height,      // height of source rectangle
   UnitPixel);
// Shrink the image using high-quality interpolation.
graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
graphics.DrawImage(
   &image,
   Rect(290, 250, 0.6 * width, 0.6 * height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle
   width,       // width of source rectangle
   height,      // height of source rectangle
   UnitPixel);

次の図は、元の画像と、3 つの縮小画像を示したものです。

大きな元の画像を示す図と、さまざまな品質の 3 つの小さな画像