参数说明:
pSrcBuffer:源图像数据
iSrcWidth: 源图像宽度
iSrcHeight:源图像高度
CropRect: 目标图像区域
pDstBuffer:目标图像数据
// 裁剪图像
void CutImage(UCHAR* pSrcBuffer, UINT iSrcWidth, UINT iSrcHeight, const CRect& CropRect,
UCHAR* pDstBuffer)
{
if (pSrcBuffer == NULL || pDstBuffer == NULL)
{
ASSERT(FALSE);
return;
}
if (CropRect.Width() > iSrcWidth || CropRect.Height() > iSrcHeight)
{
ASSERT(FALSE);
return;
}
UCHAR* pSrcBufferT = pSrcBuffer + (CropRect.left + iSrcWidth * CropRect.top) * 2;
UCHAR* pDstBufferT = pDstBuffer;
for (size_t i = 0; i < CropRect.Height(); i++)
{
memmove(pDstBufferT, pSrcBufferT, CropRect.Width() * 2);
pSrcBufferT += iSrcWidth * 2;
pDstBufferT += CropRect.Width() * 2;
}
}
参数说明:
pSrcBuffer:源图像数据
iSrcWidth: 源图像宽度
iSrcHeight:源图像高度
iDstWidth: 目标图像宽度
iDstHeight:目标图像高度
pDstBuffer:目标图像数据
// 裁剪图像
void CutImage(UCHAR* pSrcBuffer, UINT iSrcWidth, UINT iSrcHeight, UINT iDstWidth, UINT iDstHeight,
UCHAR* pDstBuffer)
{
if (pSrcBuffer == NULL || pDstBuffer == NULL)
{
ASSERT(FALSE);
return;
}
if (iDstWidth > iSrcWidth || iDstHeight > iSrcHeight)
{
ASSERT(FALSE);
return;
}
UINT iStartX = (iSrcWidth - iDstWidth) / 2;
UINT iStartY = (iSrcHeight - iDstHeight) / 2;
UCHAR* pImageCutData = (UCHAR*)pDstBuffer;
UCHAR* pSrcBufferT = pSrcBuffer + (iStartX + iSrcWidth * iStartY) * 2;
for (UINT y = iStartY; y < iStartY + iDstWidth; y++)
{
memmove(pImageCutData, pSrcBufferT, iDstWidth * 2);
pImageCutData += iDstWidth * 2;
pSrcBufferT += iSrcWidth * 2;
}
}