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

Graphics::D rawImage 方法绘制图像。

语法

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

参数

[in] image

类型: 图像*

指向指定源 图像的 Image 对象的指针。

[in, ref] destRect

类型: const RectF

对边框的引用,该矩形绑定图像的绘图区域。

[in] srcx

类型: REAL

实数,指定要绘制的源图像部分左上角的 x 坐标。

[in] srcy

类型: REAL

指定要绘制的源图像部分左上角的 y 坐标的实数。

[in] srcwidth

类型: REAL

指定要绘制的源图像部分宽度的实数。

[in] srcheight

类型: REAL

指定要绘制的源图像部分高度的实数。

[in] srcUnit

类型: 单位

指定图像度量单位的 Unit 枚举的元素。 默认值为 UnitPixel

[in] imageAttributes

类型: ImageAttributes*

指向 ImageAttributes 对象的指针,该对象指定要绘制的图像的颜色和大小属性。 默认值为 NULL。

[in] callback

类型: DrawImageAbort

用于取消正在进行的绘图的回调方法。 默认值为 NULL。

[in] callbackData

类型: VOID*

指向 由 callback 参数指定的方法使用的其他数据的指针。 默认值为 NULL。

返回值

类型: 状态

如果该方法成功,则返回 Ok,这是 Status 枚举的元素。

如果方法失败,它将返回 Status 枚举的其他元素之一。

注解

将缩放要绘制的源图像部分以适应矩形。

示例

以下示例绘制原始源图像,然后在指定矩形中绘制图像的一部分。

VOID Example_DrawImage6(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.

   REAL srcX = 70.0f;

   REAL srcY = 20.0f;

   REAL srcWidth = 100.0f;

   REAL srcHeight = 100.0f;



   // Create a RectF object that specifies the destination of the image.

   RectF destRect(200.0f, 10.0f, <REAL>image.GetWidth(), <REAL>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

单位