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

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

语法

Status DrawImage(
  [in] Image                 *image,
  [in] const Point           *destPoints,
  [in] INT                   count,
  [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
);

parameters

[in] image

类型: 图像*

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

[in] destPoints

类型: const Point*

指向 Point 对象数组的指针,该数组指定在平行四边形中绘制图像的区域。

[in] count

类型: INT

指定 destPoints 数组中的元素数的整数。

[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 枚举的其他元素之一。

注解

count 参数的值必须等于 3 才能指定平行四边形的三角。 使用第一个和第二个坐标以及第一个和第三个坐标的向量计算平行四边形的第四个角。 将缩放要绘制的源图像部分以适应平行四边形。

示例

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

VOID Example_DrawImage2(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 an array of Point objects that specify the destination of the cropped image.
   Point destPoints[3] = {
   Point(230, 30),
   Point(350, 50),
   Point(275, 120)};

   Point* pdestPoints = destPoints;

   // 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 cropped image.
   graphics.DrawImage(
   &image,
   pdestPoints,
   3,
   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