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] ImageAttributes *imageAttributes,
[in] DrawImageAbort callback,
[in] VOID *callbackData
);
imageAttributes [in]
Pointer to an ImageAttributes object that specifies the color and size attributes of the image to be drawn. The default value is NULL.
callback [in]
DrawImageAbort
Callback method used to cancel the drawing in progress. The default value is NULL. This method is called frequently to check whether to stop execution of the DrawImage method according to application-determined criteria.
callbackData [in]
VOID
Pointer to additional data used by the method specified by the callback parameter. The default value is NULL.
Remarks
The portion of the source image to be drawn is scaled to fit the parallelogram.
Demo模式
声明
BOOL CALLBACK DrawImageCallback(VOID* callbackdata);
定义
BOOL CALLBACK DrawImageCallback(VOID* callbackdata)
{
// Test for call that passes callBackData parameter.
if(reinterpret_cast<LPCTSTR>(callbackdata) == L"Not Draw")
{
// If no callBackData passed, abort DrawImage method.
return TRUE;
}
else
{
// If callBackData passed, continue DrawImage method.
return FALSE;
}
}
调用
DrawImageAbort DrawImageCallbackPtr = DrawImageCallback;
graphics.DrawImage(
&image,
destRect,
srcX,
srcY,
srcWidth,
srcHeight,
UnitPixel,
&remapAttributes,
DrawImageCallbackPtr,
L"Not Draw");
// L"Draw");
类型定义
GdiPlusTypes.h
extern "C" {
typedef BOOL (CALLBACK * ImageAbort)(VOID *);
typedef ImageAbort DrawImageAbort;
typedef ImageAbort GetThumbnailImageAbort;
}
WinDef.h
#define CALLBACK __stdcall
Test模式
BOOL CALLBACK DrawImageCallback(VOID* callbackdata)
{
int* ptrCount = reinterpret_cast<int*>(callbackdata);
if (10 == *ptrCount)
{
return TRUE;
}
else
{
++(*ptrCount);
return FALSE;
}
}
调用
int iCount = 0;
DrawImageAbort DrawImageCallbackPtr = DrawImageCallback;
graphics.DrawImage(
&image,
destRect,
srcX,
srcY,
srcWidth,
srcHeight,
UnitPixel,
&remapAttributes,
DrawImageCallbackPtr,
&iCount);
Remark
如之前的参数描述,在DrawImage过程中,DrawImageAbort会多次被调用,以时刻检查绘图过程中是否符合停止绘图的条件,一旦条件满足则停止绘图,本次绘图不产生任何图像,此时函数返回Aborted。
一个未知问题:调试DrawImage时,在DrawImageCallback里设断点,当快速连按F5时,该函数只走了几次,而慢慢点的时候则会走很多次。