📄 vcshowdlg.cpp
字号:
HV_VERIFY(status);
if (HV_SUCCESS(status)) {
m_bStart = TRUE;
}
*/
UpdateData(TRUE);
HxnDVR_UnInit();
HxnDVR_Init(m_hWnd);
// 连接第一路
HxnDVR_ConnectDevice(m_iIndex);
HxnDVR_StartCapture(m_iIndex);
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
BYTE *lpBits;
if(!HxnDVR_GetCurrentDib(m_iIndex, NULL, &rc))
return;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
int nByteWidth=w*3;
if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
HxnDVR_GetCurrentDib(m_iIndex, pBuffer1, NULL);
BITMAPINFOHEADER * pInfo = (BITMAPINFOHEADER *) pBuffer1;
//size= w * h * 3+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
//pBuffer1=new BYTE[size];
lpBits=pBuffer1+sizeof(BITMAPINFOHEADER);
int p;
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
lpBits[x*3+y*nByteWidth]=lpBits[(nByteWidth-x)*3+y*nByteWidth];
lpBits[x*3+1+y*nByteWidth]=lpBits[(nByteWidth-x)*3+1+y*nByteWidth];
lpBits[x*3+2+y*nByteWidth]=lpBits[(nByteWidth-x)*3+2+y*nByteWidth];
}
}
HDC hdc = ::GetDC(m_VideoDlg.m_hWnd);
SetStretchBltMode(hdc, COLORONCOLOR);
StretchDIBits(hdc,
346, 12, 320, 240,
0, 0, 320, 240,
lpBits, (BITMAPINFO *)pInfo, DIB_RGB_COLORS, SRCCOPY);
::ReleaseDC(m_hWnd, hdc);
//HxnDVR_SetCallBackForVideoBuffer(m_iIndex,SnapThreadCallback);
// HxnDVR_SetCallBackForVideoBuffer();
//ForVideoCallBack(0,NULL,);
// HxnDVR_SetVidCapSize(m_iIndex,128,128);
// 设置显示第一路位置
//设定指定卡号的视频图像位置,并由 HxnDVR_ShowWindow 决定是否显示。
HxnDVR_SetWindowPos(m_iIndex, m_VideoDlg.m_hWnd, NULL);
HxnDVR_ShowWindow(m_iIndex,TRUE);
}
void CVCShowDlg::RefreshDisplay()
{
InvalidateRect( NULL, TRUE );
UpdateWindow();
if( m_img->IsValid() )
{
CRect r;
CWnd *p = (CWnd*) GetDlgItem(IDC_VIDEOPRO);
CDC *pDC = p->GetDC();
p->GetWindowRect(&r);
//m_img->Stretch(pDC->m_hDC, 0, 0, r.Width(), r.Height());//360, 300
m_img->Draw(pDC->m_hDC,0, 0, 320, 240);
p->ReleaseDC(pDC);
}
}
void CVCShowDlg::OnImageStopsnap()
{
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
CString szFile;
// CString szFile,szFile1,strNamaFile;//CString strNamaFile
szFile+="c:\\test.bmp";
LPTSTR lpsz = new TCHAR[szFile.GetLength()+1];
_tcscpy(lpsz,szFile);
HRESULT hr;
hr=HxnDVR_SaveToBmpFile(m_iIndex, lpsz);
m_img= new CxImage(szFile, CXIMAGE_FORMAT_BMP);
m_img->Rotate180();
RefreshDisplay();
}
void CVCShowDlg::OnImageZhuanzhi()
{
InvalidateRect( NULL, TRUE );
UpdateWindow();
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
BYTE *lpBits;
if(!HxnDVR_GetCurrentDib(m_iIndex, NULL, &rc))
return;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
int nByteWidth=w*3;
if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
// LONG nByteWidth=(((w*8)+31)/32*4);
HxnDVR_GetCurrentDib(m_iIndex, pBuffer1, NULL);
BITMAPINFOHEADER * pInfo = (BITMAPINFOHEADER *) pBuffer1;
lpBits=pBuffer1+sizeof(BITMAPINFOHEADER);
int p;
LPBYTE lpTempPtr,lpPtr,lpSrc,lpTemp;
//lpTempPtr=new BYTE[w*h*3];
// memset(lpTempPtr,(BYTE)255,w*h*3);
// lpTemp=lpTempPtr;
//lLineBytes=w*3;
// LONG nByteWidth=(((w*8)+31)/32*4);
LONG lNewLineBytes=(((h*8)+31)/32*4);
//int lNewLineBytes=h*3;
// if (lNewLineBytes%4) lNewLineBytes+=4-(lNewLineBytes%4);
// lpTempPtr=new BYTE[w*h*3];
// lpTemp=lpTempPtr;
//nByteWidth=w*3;
lNewLineBytes=w*3;
lpTempPtr=new BYTE[w*lNewLineBytes];
lpTemp=lpTempPtr;
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
lpSrc=lpBits+y*nByteWidth+x*3;
lpTempPtr = lpTemp + lNewLineBytes*(x)+y*3;
*lpTempPtr++=lpBits[x*3+y*nByteWidth];
*lpTempPtr++=lpBits[x*3+y*nByteWidth+1];
*lpTempPtr=lpBits[x*3+y*nByteWidth+2];
lpTempPtr=lpTemp;
/*lpTemp[x*3+y*nByteWidth]=lpBits[(w-1-x)*3+(h-y-1)*nByteWidth];
lpTemp[x*3+1+y*nByteWidth]=lpBits[(w-1-x)*3+1+(h-y-1)*nByteWidth];
lpTemp[x*3+2+y*nByteWidth]=lpBits[(w-1-x)*3+2+(h-y-1)*nByteWidth];*/
}
}
memcpy(lpBits, lpTemp, w* h*3);
//lpBits=lpTemp;
HDC hdc = ::GetDC(m_Videopro.m_hWnd);
SetStretchBltMode(hdc, COLORONCOLOR);
StretchDIBits(hdc,
0, 0, 360, 300,
0, 0, 320, 240,
lpBits, (BITMAPINFO *)pInfo, DIB_RGB_COLORS, SRCCOPY);
::ReleaseDC(m_hWnd, hdc);
// UpdateData(TRUE);
// Invalidate();346,12
// Invalidate(); //调用刷新函数
}
void CVCShowDlg::OnCorner()
{
InvalidateRect( NULL, TRUE );
UpdateWindow();
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
BYTE *lpBits;
if(!HxnDVR_GetCurrentDib(m_iIndex, NULL, &rc))
return;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
int nByteWidth=w*3;
if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
// LONG nByteWidth=(((w*8)+31)/32*4);
HxnDVR_GetCurrentDib(m_iIndex, pBuffer1, NULL);
BITMAPINFOHEADER * pInfo = (BITMAPINFOHEADER *) pBuffer1;
lpBits=pBuffer1+sizeof(BITMAPINFOHEADER);
int p;
LPBYTE lpTempPtr,lpPtr,lpSrc,lpTemp;
LONG lNewLineBytes=(((h*8)+31)/32*4);
lNewLineBytes=w*3;
lpTempPtr=new BYTE[h*lNewLineBytes];
lpTemp=lpTempPtr;
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
lpTemp[x*3+y*nByteWidth]=lpBits[(w-1-x)*3+(h-y-1)*nByteWidth];
lpTemp[x*3+1+y*nByteWidth]=lpBits[(w-1-x)*3+1+(h-y-1)*nByteWidth];
lpTemp[x*3+2+y*nByteWidth]=lpBits[(w-1-x)*3+2+(h-y-1)*nByteWidth];
}
}
memcpy(lpBits, lpTemp, w* h*3);
//lpBits=lpTemp;
HDC hdc = ::GetDC(m_Videopro.m_hWnd);
SetStretchBltMode(hdc, COLORONCOLOR);
StretchDIBits(hdc,
0, 0, 320, 240,
0, 0, 320, 240,
lpBits, (BITMAPINFO *)pInfo, DIB_RGB_COLORS, SRCCOPY);
::ReleaseDC(m_hWnd, hdc);
}
void CVCShowDlg::OnImageEdge()
{
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
CString szFile;
// CString szFile,szFile1,strNamaFile;//CString strNamaFile
szFile+="c:\\test.bmp";
LPTSTR lpsz = new TCHAR[szFile.GetLength()+1];
_tcscpy(lpsz,szFile);
HRESULT hr;
hr=HxnDVR_SaveToBmpFile(m_iIndex, lpsz);
m_img= new CxImage(szFile, CXIMAGE_FORMAT_BMP);
m_img->Edge();
RefreshDisplay();
}
void CVCShowDlg::OnImageGamma()
{
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
CString szFile;
// CString szFile,szFile1,strNamaFile;//CString strNamaFile
szFile+="c:\\test.bmp";
LPTSTR lpsz = new TCHAR[szFile.GetLength()+1];
_tcscpy(lpsz,szFile);
HRESULT hr;
hr=HxnDVR_SaveToBmpFile(m_iIndex, lpsz);
m_img= new CxImage(szFile, CXIMAGE_FORMAT_BMP);
m_img->Gamma(1.2);
RefreshDisplay();
}
void CVCShowDlg::OnImagePseudocolors()
{
InvalidateRect( NULL, TRUE );
UpdateWindow();
int x,y;
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
BYTE *lpBits;
if(!HxnDVR_GetCurrentDib(m_iIndex, NULL, &rc))
return;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
int nByteWidth=w*3;
if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
HxnDVR_GetCurrentDib(m_iIndex, pBuffer1, NULL);
BITMAPINFOHEADER * pInfo = (BITMAPINFOHEADER *) pBuffer1;
//size= w * h * 3+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
//pBuffer1=new BYTE[size];
lpBits=pBuffer1+sizeof(BITMAPINFOHEADER);
BYTE b,R,G,B;
for(y=0;y<h;y++)
{
for(x=0;x<w;x++)
{
b=lpBits[nByteWidth * (y)+(x)*3];
if (b<64)
{
B=255;
G=4*b;
R=0;
}
else if (b<128)
{
B=(127-b)*4;
G=255;
R=0;
}
else if (b<192)
{
B=0;
G=255;
R=(b-128)*4;
}
else
{
B=0;
G=(255-b)*4;
R=255;
}
lpBits[nByteWidth * (y)+(x)*3]=B;
lpBits[nByteWidth * (y)+(x)*3+1]=G;
lpBits[nByteWidth * (y)+(x)*3+2]=R;
}
}
HDC hdc = ::GetDC(m_Videopro.m_hWnd);
SetStretchBltMode(hdc, COLORONCOLOR);
StretchDIBits(hdc,
0, 0, 320, 240,
0, 0, 320, 240,
lpBits, (BITMAPINFO *)pInfo, DIB_RGB_COLORS, SRCCOPY);
::ReleaseDC(m_hWnd, hdc);
}
void CVCShowDlg::OnColorsplit()
{
CColorSplitDlg dlg; // 创建对话框
Splitcolor splitdlg;
CxImage *newr = new CxImage();
CxImage *newg = new CxImage();
CxImage *newb = new CxImage();
CString szFile;
szFile+="c:\\test.bmp";
LPTSTR lpsz = new TCHAR[szFile.GetLength()+1];
_tcscpy(lpsz,szFile);
CxImage *newa;
newa=NULL;
CxImage *mix = new CxImage();
HRESULT hr;
hr=HxnDVR_SaveToBmpFile(m_iIndex, lpsz);
m_img= new CxImage(szFile, CXIMAGE_FORMAT_BMP);
m_img->SplitRGB(newr,newg,newb);
dlg.newr=newr;
dlg.newg=newg;
dlg.newb=newb;
if (splitdlg.DoModal() != IDOK)
{
return;// 返回
}
int a;
a=splitdlg.m_split;
switch(a)
{
case 0:
{
m_img->SplitRGB(newr,newg,newb);
dlg.newr=newr;
dlg.newg=newg;
dlg.newb=newb;
}
break;
case 1:
{
m_img->SplitHSL(newr,newg,newb);
dlg.newr=newr;
dlg.newg=newg;
dlg.newb=newb;
}
break;
case 2:
{
m_img->SplitYUV(newr,newg,newb);
dlg.newr=newr;
dlg.newg=newg;
dlg.newb=newb;
}
break;
case 3:
{
m_img->SplitYIQ(newr,newg,newb);
dlg.newr=newr;
dlg.newg=newg;
dlg.newb=newb;
}
break;
default:
break;
}
mix->Combine(newr,newg,newb,newa,0);
dlg.mix=mix;
if (dlg.DoModal() != IDOK)
{
return;// 返回
}
// mix->Combine(newr,newg,newb,newa,dlg.pChS);
// TODO: Add your control notification handler code here
}
void CVCShowDlg::OnImageGray()
{
InvalidateRect( NULL, TRUE );
UpdateWindow();
RECT rc= {10,10,320,240};
BYTE * pBuffer1 = NULL;
BYTE *lpBits;
if(!HxnDVR_GetCurrentDib(m_iIndex, NULL, &rc))
return;
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int size = w * h * 3 + sizeof(BITMAPINFOHEADER);
pBuffer1 = new BYTE[ size ];
int nByteWidth=w*3;
if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
HxnDVR_GetCurrentDib(m_iIndex, pBuffer1, NULL);
BITMAPINFOHEADER * pInfo = (BITMAPINFOHEADER *) pBuffer1;
//size= w * h * 3+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
//pBuffer1=new BYTE[size];
lpBits=pBuffer1+sizeof(BITMAPINFOHEADER);
int p;
BYTE Point;
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
p=x*3+y*nByteWidth;
Point=(BYTE)(0.299*(float)lpBits[p+2]+0.587*(float)lpBits[p+1]+0.114*(float)lpBits[p]+0.1);
lpBits[x*3+y*nByteWidth]=Point;
lpBits[x*3+1+y*nByteWidth]=Point;
lpBits[x*3+2+y*nByteWidth]=Point;
}
}
HDC hdc = ::GetDC(m_Videopro.m_hWnd);
SetStretchBltMode(hdc, COLORONCOLOR);
StretchDIBits(hdc,
0, 0, 320, 240,
0, 0, 320, 240,
lpBits, (BITMAPINFO *)pInfo, DIB_RGB_COLORS, SRCCOPY);
::ReleaseDC(m_hWnd, hdc);
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -