图形::D rawImage (Image*,constPointF*,INT,REAL,REAL,REAL,REAL,REAL,Unit,constImageAttributes*,DrawImageAbort,VOID*) 方法 (gdiplusgraphics.h)
Graphics::D rawImage 方法绘制图像。
语法
Status DrawImage(
[in] Image *image,
[in] const PointF *destPoints,
[in] INT count,
[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] destPoints
类型: const PointF*
指向 PointF 对象数组的指针,该数组指定在平行四边形中绘制图像的区域。
[in] count
类型: INT
指定 destPoints 数组中的元素数的整数。
[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*
指向 由回调 参数指定的方法使用的其他数据的指针。 默认值为 NULL。
返回值
类型: 状态
如果方法成功,则返回 Ok,这是 Status 枚举的元素。
如果 方法失败,它将返回 Status 枚举的其他元素之一。
注解
count 参数的值必须等于 3,以指定平行四边形左上角、右上角和左下角的坐标。 右下角的坐标是使用图像的三个给定坐标、宽度和高度计算的。 将缩放要绘制的源图像部分以适应平行四边形。
示例
以下示例绘制原始源图像,然后在指定的平行四边形中绘制图像的一部分。
VOID Example_DrawImage4(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 an array of Point objects that specify the destination of the cropped image.
PointF destPoints[3] = {
PointF(230.0f, 30.0f),
PointF(350.0f, 50.0f),
PointF(275.0f, 120.0f)};
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 |
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈