Share via


Graphics::D rawImage (Image*,constRect&,INT,INT,INT,Unit,constImageAttributes*,DrawImageAbort,VOID*) 方法 (gdiplusgraphics.h)

Graphics::D rawImage 方法會繪製影像。

語法

Status DrawImage(
  [in]      Image                 *image,
  [in, ref] const Rect &          destRect,
  [in]      INT                   srcx,
  [in]      INT                   srcy,
  [in]      INT                   srcwidth,
  [in]      INT                   srcheight,
  [in]      Unit                  srcUnit,
  [in]      const ImageAttributes *imageAttributes,
  [in]      DrawImageAbort        callback,
  [in]      VOID                  *callbackData
);

參數

[in] image

類型: 影像*

指定來源影像之 Image 物件的指標。

[in, ref] destRect

類型: const Rect

系結影像繪圖區域的矩形參考。

[in] srcx

類型: INT

整數,指定要繪製之來源影像部分左上角的 X 座標。

[in] srcy

類型: INT

整數,指定要繪製之來源影像部分左上角的 Y 座標。

[in] srcwidth

類型: INT

整數,指定要繪製之來源影像部分的寬度。

[in] srcheight

類型: INT

整數,指定要繪製之來源影像部分的高度。

[in] srcUnit

類型: 單位

Unit 列舉的 元素,指定影像的測量單位。 預設值為 UnitPixel

[in] imageAttributes

類型: ImageAttributes*

ImageAttributes 物件的指標,指定要繪製之影像的色彩和大小屬性。 預設值是 NULL

[in] callback

類型: DrawImageAbort

用來取消進行中繪圖的回呼方法。 預設值是 NULL

[in] callbackData

類型: VOID*

參數所指定方法所使用的其他數據的指標。 預設值是 NULL

傳回值

類型: 狀態

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

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

備註

要繪製的來源影像部分會縮放以符合矩形。

範例

下列範例會繪製原始來源影像,然後在指定的矩形中繪製影像的一部分。

VOID Example_DrawImage5(HDC hdc)

{
   Graphics graphics(hdc);

   // Create an Image object.
   Image image(L"pattern.png");

   // Draw the original source image.
   graphics.DrawImage(&image, 10, 10);

   // Define the portion of the image to draw.
   int srcX = 70;
   int srcY = 20;
   int srcWidth = 100;
   int srcHeight = 100;

   // Create a Rect object that specifies the destination of the image.
   Rect destRect(200, 10, image.GetWidth(), image.GetHeight());

   // Create an ImageAttributes object that specifies a recoloring from red to blue.
   ImageAttributes remapAttributes;
   ColorMap redToBlue;
   redToBlue.oldColor = Color(255, 255, 0, 0);
   redToBlue.newColor = Color(255, 0, 0, 255);
   remapAttributes.SetRemapTable(1, &redToBlue);

   // Draw the resized image.
   graphics.DrawImage(
   &image,
   destRect,
   srcX,
   srcY,
   srcWidth,
   srcHeight,
   UnitPixel,
   &remapAttributes,
   NULL,
   NULL);
}

下圖顯示上述程式代碼的輸出。

顯示兩個圖形的圖例:多色的棋盤圖樣,然後從該圖樣放大雙色

規格需求

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

另請參閱

繪製、定位和複製影像

圖形

映像

ImageAttributes

載入和顯示點陣圖

SetRemapTable

單位