Graphics::D rawImage (Image*,constRect&,INT,INT,INT,INT,单位,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)
Library Gdiplus.lib
DLL Gdiplus.dll

另请参阅

绘制、定位和复制图像

显卡

图像

ImageAttributes

加载和显示位图

Point

SetRemapTable

单位