Image::GetBounds メソッド (gdiplusheaders.h)

Image::GetBounds メソッドは、このイメージの外接する四角形を取得します。

構文

Status GetBounds(
  [out] RectF *srcRect,
  [out] Unit  *srcUnit
);

パラメーター

[out] srcRect

種類: RectF*

外接する四角形を受け取る RectF オブジェクトへのポインター。

[out] srcUnit

種類: 単位*

外接する四角形の測定単位を示す Unit 列挙体の要素を受け取る変数へのポインター。

戻り値

種類: 状態

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

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

注釈

メタファイルの外接する四角形の左上隅に (0, 0) が含まれているとは限りません。 左上隅の座標は、メタファイルの記録中に発行された描画コマンドに応じて、負または正にすることができます。 たとえば、メタファイルが、次のステートメントで記録された 1 つの省略記号で構成されるとします。

DrawEllipse(&pen, 200, 100, 80, 40);

その後、メタファイルの外接する四角形は、その 1 つの楕円を囲みます。 外接する四角形の左上隅は (0, 0) ではありません。むしろ、それは近い点になります(200、100)。

次の例では、メタファイルに基づいて Image オブジェクトを作成し、イメージを描画します。 次に、 Image::GetBounds メソッドを呼び出して、イメージの外接する四角形を取得します。 このコードでは、画像の 75% を表示するために 2 回試行します。 最初の試行は、ソース四角形の左上隅に (0, 0) を指定するため失敗します。 2 回目の試行は成功します。これは、Image::GetBounds によって返される X データ メンバーと Y データ メンバーを使用して、ソース四角形の左上隅を指定するためです。

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

   Image image(L"SampleMetafile2.emf");
   graphics.DrawImage(&image, 0, 0);

   // Get the bounding rectangle for the image (metafile).
   RectF boundsRect;
   Unit unit;
   image.GetBounds(&boundsRect, &unit);

   // Attempt to draw 75 percent of the image.
   // Less than 75 percent of the image will be visible because the
   // upper-left corner of the image's bounding rectangle is not (0, 0).
   RectF dstRect(250.0f, 0.0f, 100.0f, 50.0f);
   graphics.DrawImage(
      &image,
      dstRect,                  // destination rectangle
      0.0f, 0.0f,               // upper-left corner of source rectangle 
      0.75f*boundsRect.Width,   // width of source rectangle
      boundsRect.Height,        // height of source rectangle
      UnitPixel);

   // Draw 75 percent of the image.
   dstRect.Y = 80.0f;
   graphics.DrawImage(
      &image,
      dstRect,                       // destination rectangle
      boundsRect.X, boundsRect.Y,    // upper-left corner of source rectangle
      0.75f*boundsRect.Width,        // width of source rectangle
      boundsRect.Height,             // height of source rectangle
      UnitPixel);
}

上記のコードは、特定のファイルと共にSampleMetafile2.emf、次の出力を生成しました。 画像の 75% を描画する最初の試行 (右上) では、画像の約 30% のみが表示されることに注意してください。

3 つの楕円の部分を示すスクリーン ショット:最初の 1 つすべて、2 番目の 30%、3 番目の楕円の 75%

要件

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

こちらもご覧ください

Image

Image::GetHeight

Image::GetWidth

イメージ、ビットマップ、メタファイル

RectF

単位

イメージ、ビットマップ、メタファイルの使用