Image::GetBounds 方法 (gdiplusheaders.h)

Image::GetBounds 方法會取得此影像的周框。

語法

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

參數

[out] srcRect

類型: RectF*

接收周框之 RectF 物件的指標。

[out] srcUnit

類型: 單位*

變數的指標,該變數會接收 Unit 列舉的元素,指出周框的量值單位。

傳回值

類型: 狀態

如果方法成功,它會傳回Ok,這是 Status 列舉的元素。

如果方法失敗,它會傳回 Status 列舉的其中一個其他元素。

備註

元檔周框不一定有 (0,0) 做為其左上角。 左上角的座標可以是負數或正數,視在錄製元文件期間發出的繪圖命令而定。 例如,假設元檔是由使用下列語句記錄的單一省略號所組成:

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

然後,元檔周框會括住該省略號。 周框左上角不會 (0,0) ;相反地,它會是接近 (200,100) 點。

範例

下列範例會根據元檔建立 Image 對象,然後繪製影像。 接下來,程式代碼會呼叫 Image::GetBounds 方法來取得影像的周框。 程式代碼會嘗試顯示 75% 的影像。 第一次嘗試失敗,因為它指定來源矩形左上角的 (0,0) 。 第二次嘗試成功,因為它使用 Image::GetBounds 傳回的 XY 資料成員來指定來源矩形的左上角。

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% 的影像。

顯示三個省略號部分的螢幕快照:第一個省略號的所有部分、第二個 30% 和第三個省略號的 75%。

規格需求

需求
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平台 Windows
標頭 gdiplusheaders.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

映像

Image::GetHeight

Image::GetWidth

影像、點陣圖和中繼檔

RectF

單位

使用影像、位圖和元檔