📄 vcshowdlg.cpp
字号:
CString szFileA;
if(FileDialog(szFileA)){
szFileA+=".avi";
LPTSTR lpsz = new TCHAR[szFileA.GetLength()+1];
_tcscpy(lpsz,szFileA);
m_Sync.Lock();
if (m_bUseAudio)
{
// 捕获MPEG4音视频数据
HxnDVR_SetCaptureFile(m_iIndex, lpsz, CaptureMode_VA_MPEG4_FILE);
}
else
{
// 捕获MPEG4视频数据
HxnDVR_SetCaptureFile(m_iIndex, lpsz, CaptureMode_VO_MPEG4_FILE);
}
// 只捕获音频数据
// HxnDVR_SetCaptureFile(m_iIndex, tmpstr, CaptureMode_AO_WAV_FILE);
// 捕获音视频分离数据
// HxnDVR_SetCaptureFile(m_iIndex, tmpstr, (DWORD) CaptureMode_VO_MPEG4_FILE | CaptureMode_AO_WAV_FILE);
HxnDVR_StartCapture(m_iIndex);
m_Sync.Unlock();
GetDlgItem(IDC_CAPTURES)->SetWindowText("停止");
GetDlgItem(IDC_SET_CAPSIZE)->EnableWindow(FALSE);
}
}
else
{
// 停止录像
m_Sync.Lock();
HxnDVR_StopCapture(m_iIndex);
m_Sync.Unlock();
GetDlgItem(IDC_CAPTURES)->SetWindowText("录像");
GetDlgItem(IDC_SET_CAPSIZE)->EnableWindow(TRUE);
}
}
void CVCShowDlg::OnMpegPar()
{
// TODO: Add your control notification handler code here
if (! HxnDVR_IsConnected(m_iIndex))
{
return;
}
// 1、位率设置要求
// 320 X 240 一般不小于 128
// 640 X 480 一般不小于 512 最好为 1024 以上
// 2、I帧间距 >= 所设的帧率
CCsetting m_ParDlg;
m_ParDlg.DoModal();
}
void CVCShowDlg::OnCheckUseAudio()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CVCShowDlg::OnBtGetCardid()
{
// TODO: Add your control notification handler code here
BYTE m_txt[32];
HxnDVR_GetCurrentCardID(m_txt);
AfxMessageBox((char *)m_txt);
}
void CVCShowDlg::OnCapturepic()
{
/* CString szFileB,szFileJ;
HRESULT hr;
if(FileDialog(szFileB)){
szFileJ=szFileB;
szFileB+=".bmp";
szFileJ+=".jpg";
LPTSTR lpsz = new TCHAR[szFileB.GetLength()+1];
_tcscpy(lpsz,szFileB);
hr = HxnDVR_SaveToBmpFile(m_iIndex, lpsz);
if(FAILED(hr))
MessageBox("BMP快照失败!");
_tcscpy(lpsz,szFileJ);
hr = HxnDVR_SaveToJpgFile(m_iIndex, lpsz, 65);
if(FAILED(hr))
MessageBox("JPG快照失败!");*/
DibShow();
}
void CVCShowDlg::DibShow()
{
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);
if(pBuffer1)
{
HxnDVR_GetCurrentDib(m_iIndex, pBuffer1, NULL);
BITMAPINFOHEADER * pInfo = (BITMAPINFOHEADER *) pBuffer1;
lpBits=pBuffer1+sizeof(BITMAPINFOHEADER);
/* for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
int p;
p=lpBits[y*nByteWidth+x*3];
lpBits[y*nByteWidth+x*3]=lpBits[y*nByteWidth+x*3];
lpBits[y*nByteWidth+x*3+1]=lpBits[y*nByteWidth+x*3+1];
lpBits[y*nByteWidth+x*3+2]=lpBits[y*nByteWidth+x*3+2];
}
}*/
HDC hdc = ::GetDC(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);
}
}
bool CVCShowDlg::FileDialog(CString &filename)
{
CFileDialog dlg(false,NULL,NULL,OFN_OVERWRITEPROMPT,"(*.bmp;*.jpg;*.avi)|*.bmp;*.jpg;*.avi||");
dlg.m_ofn.lpstrTitle="选择存盘路径";
if(dlg.DoModal()==IDOK){
filename=dlg.GetPathName();
int n=filename.ReverseFind('.');
if(n>1) filename.Insert(n,'\0');
m_imagCtrl.ConvertPath(filename);
return true;
}
else return false;
}
void CVCShowDlg::OnSeries()
{
if(series_flag==0){
SeriesSnapDlg dlg;
if(dlg.DoModal()==IDOK){
charPath=dlg.m_path;
SetTimer(1,dlg.m_NumTime*40+40,NULL);
GetDlgItem(IDC_SERIES)->SetWindowText("停止采集");
series_flag=(!series_flag);
}
}
else{
GetDlgItem(IDC_SERIES)->SetWindowText("采序列");
KillTimer(1);
series_flag=(!series_flag);
}
}
void CVCShowDlg::OnTimer(UINT nIDEvent)
{
tempPath=charPath;
ConvertName(tempPath,capName);
LPTSTR lpsz = new TCHAR[tempPath.GetLength()+1];
_tcscpy(lpsz,tempPath);
HxnDVR_SaveToBmpFile(m_iIndex, lpsz);
capName++;
CDialog::OnTimer(nIDEvent);
}
void CVCShowDlg::ConvertName(CString &charPathName, int capName)
{
CString temp;
temp.Format("%d%c%04d",m_iIndex,'-',capName);
charPathName+=temp;
charPathName+=".bmp";
}
bool CVCShowDlg::ReConfigCard(int x,int y)
{
HxnDVR_GetVidCapSize(m_iIndex, (unsigned long *)&m_ulCapWidth, (unsigned long *)&m_ulCapHeight);
if(m_ulCapWidth==768&&m_ulCapHeight==576){
HxnDVR_SetVidCapSize(m_iIndex,x, y);
return true;
}
else
return false;
}
bool CVCShowDlg::TReConfigCard(int x,int y)
{
//获取显示、快照视频尺寸大小
HxnDVR_GetVidCapSize(m_iIndex, (unsigned long *)&m_ulCapWidth, (unsigned long *)&m_ulCapHeight);
if(m_ulCapWidth==768&&m_ulCapHeight==288){
HxnDVR_SetVidCapSize(m_iIndex,x, y);
return true;
}
else
return false;
}
void CVCShowDlg::OnSingleImage()
{
bool flag;
CString szFile;
flag=ReConfigCard(768,288);
if(FileDialog(szFile)){
szFile+=".bmp";
InnerSaveBmp(szFile,flag);
}
TReConfigCard(768,576);
}
void CVCShowDlg::InnerSaveBmp(CString szFileD,bool flag)
{
//存为bmp格式
HRESULT hr;
LPTSTR lpsz = new TCHAR[szFileD.GetLength()+1];
_tcscpy(lpsz,szFileD);
if(flag!=true)
hr = HxnDVR_SaveToBmpFile(m_iIndex, lpsz);
//存为dib格式
else{
BITMAPFILEHEADER bfHdr;
long size=0;
BYTE * pImageMem=NULL;
size=768*288*3*sizeof(BYTE)+sizeof(BITMAPINFOHEADER);
//读取dib数据
pImageMem = (BYTE*)malloc(size);
hr=HxnDVR_GetCurrentDib(m_iIndex, pImageMem, NULL);
size=768*576*3*sizeof(BYTE);
BYTE *pImageMemEn=(BYTE*)malloc(size);
m_imagCtrl.EnlargeDataInt(pImageMem+40,768,288,pImageMemEn,768,576);
//文件头信息设置
bfHdr.bfReserved1 = 0;
bfHdr.bfReserved2 = 0;
bfHdr.bfType = 0x4D42;
bfHdr.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
BITMAPINFO* tfc=(BITMAPINFO* )pImageMem;
tfc->bmiHeader.biWidth=768;
tfc->bmiHeader.biHeight=576;
tfc->bmiHeader.biSizeImage=768*576*3;
//写文件
FILE *fp;
fp = fopen(szFileD, "wb");
if (fp != NULL)
{
fwrite(&bfHdr, 1, sizeof(BITMAPFILEHEADER), fp);
fwrite(pImageMem, 1, 40, fp);
fwrite(pImageMemEn, 1, size, fp);
}
fclose(fp);
free(pImageMem);
free(pImageMemEn);
}
if(FAILED(hr))
MessageBox("快照失败!");
}
void CVCShowDlg::OnImageRotate()
{
InvalidateRect( NULL, TRUE );
UpdateWindow();
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);
float RotateAngle;
CRotateDlg dlg; // 创建对话框
// dlg.m_Rotate_Angle = 90; // 初始化变量值
// 显示对话框,提示用户设定旋转角度
if (dlg.DoModal() != IDOK)
{
return;// 返回
}
// 获取用户设定的旋转量
RotateAngle = dlg.m_Rotate_Angle;
m_img->Rotate(RotateAngle);
RefreshDisplay();
}
void CVCShowDlg::OnImageHflip()
{
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;
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_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::OnImageVflip()
{
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;
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;
for(int x=0;x<w;x++)
{
for(int y=0;y<h;y++)
{
lpTempPtr = lpTemp + nByteWidth * ( y)+x*3;
*lpTempPtr++=lpBits[x*3+(h-y-1)*nByteWidth];
*lpTempPtr++=lpBits[x*3+1+(h-y-1)*nByteWidth];
*lpTempPtr=lpBits[x*3+2+(h-y-1)*nByteWidth];
lpTempPtr=lpTemp;
}
}
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);
UpdateData(TRUE);
}
void CVCShowDlg::OnImageFilter()
{
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;
lpBits=pBuffer1+sizeof(BITMAPINFOHEADER);
int i,j;
LPBYTE lpSrc;
LPBYTE lpDst;
LPBYTE m_Dst_data;
m_Dst_data=new BYTE[w*h*3];
memset(m_Dst_data,255,w*h*3);
BYTE p[9];
BYTE p1[9];
BYTE p2[9];
int k,k1,s,s1,s2;
for(j=1;j<h-1;j++)
{
for(i=1;i<w-1;i++)
{
lpDst=(LPBYTE)m_Dst_data+nByteWidth*j+i*3;
lpSrc = lpBits + nByteWidth * (j-1)+(i-1)*3;
p[0]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i)*3;
p[1]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i+1)*3;
p[2]=*lpSrc;
lpSrc = lpBits + nByteWidth* (j)+(i-1)*3;
p[3]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j)+(i)*3;
p[4]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j)+(i+1)*3;
p[5]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i-1)*3;
p[6]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i)*3;
p[7]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i+1)*3;
p[8]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i-1)*3+1;
p1[0]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i)*3+1;
p1[1]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i+1)*3+1;
p1[2]=*lpSrc;
lpSrc = lpBits + nByteWidth* (j)+(i-1)*3+1;
p1[3]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j)+(i)*3+1;
p1[4]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j)+(i+1)*3+1;
p1[5]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i-1)*3+1;
p1[6]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i)*3+1;
p1[7]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i+1)*3+1;
p1[8]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i-1)*3+2;
p2[0]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i)*3+2;
p2[1]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j-1)+(i+1)*3+2;
p2[2]=*lpSrc;
lpSrc = lpBits + nByteWidth* (j)+(i-1)*3+2;
p2[3]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j)+(i)*3+2;
p2[4]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j)+(i+1)*3+2;
p2[5]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i-1)*3+2;
p2[6]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i)*3+2;
p2[7]=*lpSrc;
lpSrc = lpBits + nByteWidth * (j+1)+(i+1)*3+2;
p2[8]=*lpSrc;
for(k=0;k<5;k++)
{
for(k1=k+1;k1<9;k1++)
{
if (p[k]>p[k1])
{
s=p[k];
p[k]=p[k1];
p[k1]=s;
s1=p1[k];
p1[k]=p1[k1];
p1[k1]=s1;
s2=p2[k];
p2[k]=p2[k1];
p2[k1]=s2;
}
}
}
//lpSrc = (LPBYTE)m_pBits + width * j+i;
//*lpSrc=p[4];
*lpDst++=(BYTE)p[4];
*lpDst++=(BYTE)p1[4];
*lpDst=(BYTE)p2[4];
}
}
lpBits=m_Dst_data;
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::OnImageSnap()
{
/*
BYTE *ppBuf[1];
ppBuf[0] = m_pRawBuffer;
status = HVStartSnap(m_hhv, ppBuf,1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -