16,472
社区成员
发帖
与我相关
我的任务
分享
void WINAPI PreviewCallback(HDC hDC,
unsigned char *pImageData,
int nWidth,
int nHeight,
int nBitCount,
void *lpContext)
{
CKYDCamera * pF = (CKYDCamera*)lpContext;
if (pF->bCrossLine)
{
CPen Pen;
if (pF->iCLColor == 0)//白色
Pen.CreatePen(PS_SOLID,pF->iCLPixel,RGB(255,255,255));
else if (pF->iCLColor == 1)//黑色
Pen.CreatePen(PS_SOLID,pF->iCLPixel,RGB(0,0,0));
POINT Pcenter;
Pcenter.x = nWidth>>1;
Pcenter.y = nHeight>>1;
::SelectObject(hDC,Pen);
::MoveToEx(hDC,0,Pcenter.y,NULL);
::LineTo(hDC,nWidth,Pcenter.y);
::MoveToEx(hDC,Pcenter.x,0,NULL);
::LineTo(hDC,Pcenter.x,nHeight);
int iGap = nWidth/pF->iSpacing;
for(int i=1;i<pF->iDividing;i++)//先画横向
{
if (i%2 != 0)//余数不等于0,画短的
{
::MoveToEx(hDC,Pcenter.x-i*iGap,Pcenter.y+iGap/2,NULL);//左边的
::LineTo(hDC,Pcenter.x-i*iGap,Pcenter.y-iGap/2);
::MoveToEx(hDC,Pcenter.x+i*iGap,Pcenter.y+iGap/2,NULL);//右边的
::LineTo(hDC,Pcenter.x+i*iGap,Pcenter.y-iGap/2);
}
else//画长的
{
::MoveToEx(hDC,Pcenter.x-i*iGap,Pcenter.y+iGap,NULL);//上边的
::LineTo(hDC,Pcenter.x-i*iGap,Pcenter.y-iGap);
::MoveToEx(hDC,Pcenter.x+i*iGap,Pcenter.y+iGap,NULL);//下边的
::LineTo(hDC,Pcenter.x+i*iGap,Pcenter.y-iGap);
}
}
iGap = nHeight/pF->iSpacing;
for(int i=1;i<pF->iDividing;i++)//画纵向
{
if (i%2 != 0)//余数不等于0,画短的
{
::MoveToEx(hDC,Pcenter.x+iGap/2,Pcenter.y-i*iGap,NULL);//左边的
::LineTo(hDC,Pcenter.x-iGap/2,Pcenter.y-i*iGap);
::MoveToEx(hDC,Pcenter.x+iGap/2,Pcenter.y+i*iGap,NULL);//右边的
::LineTo(hDC,Pcenter.x-iGap/2,Pcenter.y+i*iGap);
}
else//画长的
{
::MoveToEx(hDC,Pcenter.x+iGap,Pcenter.y-i*iGap,NULL);//上边的
::LineTo(hDC,Pcenter.x-iGap,Pcenter.y-i*iGap);
::MoveToEx(hDC,Pcenter.x+iGap,Pcenter.y+i*iGap,NULL);//下边的
::LineTo(hDC,Pcenter.x-iGap,Pcenter.y+i*iGap);
}
}
}
}
::SelectObject(hDC,Pen);
这里应该保存老的画笔指针,在你画完后,应该恢复现场。