The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
BitBlt函数执行将对应于像素矩形的颜色数据从指定的源设备上下文到目标设备上下文的位块传输。
句法
BOOL BitBlt(
[in] HDC hdc,
[in] int x,
[in] int y,
[in] int cx,
[in] int cy,
[in] HDC hdcSrc,
[in] int x1,
[in] int y1,
[in] DWORD rop
);
参数
[in] hdc
A handle to the destination device context.
目标设备上下文的句柄。
[in] x
The x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
目标矩形左上角的 x 坐标(以逻辑单位表示)。
[in] y
The y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
目标矩形左上角的 y 坐标(以逻辑单位表示)。
[in] cx
The width, in logical units, of the source and destination rectangles.
源矩形和目标矩形的宽度(以逻辑单位表示)。
[in] cy
The height, in logical units, of the source and the destination rectangles.
源矩形和目标矩形的高度(以逻辑单位表示)。
[in] hdcSrc
A handle to the source device context.
源设备上下文的句柄。
[in] x1
The x-coordinate, in logical units, of the upper-left corner of the source rectangle.
源矩形左上角的 x 坐标(以逻辑单位表示)。
[in] y1
The y-coordinate, in logical units, of the upper-left corner of the source rectangle.
源矩形左上角的 y 坐标(以逻辑单位表示)。
[in] rop
光栅操作代码。这些代码定义了如何将源矩形的颜色数据与目标矩形的颜色数据组合以实现最终颜色。
以下列表显示了一些常见的光栅操作代码。
返回值
如果函数成功,则返回值非零。
如果函数失败,则返回值为零。要获取扩展的错误信息,请调用GetLastError。
说明
BitBlt仅在目标 DC 上进行剪辑。
如果旋转或剪切变换在源设备上下文中生效,BitBlt将返回错误。如果源设备上下文中存在其他转换(并且匹配的转换在目标设备上下文中无效),则目标设备上下文中的矩形将根据需要进行拉伸、压缩或旋转。
如果源和目标设备上下文的颜色格式不匹配,BitBlt函数将源颜色格式转换为与目标格式匹配。
记录增强元文件时,如果源设备上下文标识增强元文件设备上下文,则会发生错误。
并非所有设备都支持BitBlt功能。有关详细信息,请参阅GetDeviceCaps函数中的 RC_BITBLT 栅格功能条目以及以下函数:MaskBlt、PlgBlt和StretchBlt。
如果源设备上下文和目标设备上下文表示不同的设备, BitBlt将返回错误。要在不同设备的 DC 之间传输数据,请通过调用GetDIBits将内存位图转换为 DIB 。要将 DIB 显示到第二个设备,请调用SetDIBits或StretchDIBits。
ICM:出现 blits 时不执行颜色管理。
例子
下面的代码示例演示了BitBlt的使用。
if (!BitBlt(hdcMemDC,
0, 0,
rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
hdcWindow,
0, 0,
SRCCOPY))
{
MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK);
goto done;
}
要在上下文中查看此示例,请参阅捕获图像。
要求
Minimum supported client | Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | wingdi.h (include Windows.h) |
Library | Gdi32.lib |
DLL | Gdi32.dll |