Exemplo n.º 1
0
int CHikVision::CaptureJpeg( HANDLE hChannel, QString& strFile )
{
    int nRet = 0;
    ULONG lSize = 1024 * 1024 * 1;
    PUCHAR pImgBuff = new UCHAR[ lSize ];
    nRet = GetJpegImage( hChannel, pImgBuff, &lSize, 65 );
    if ( 0 != nRet ) {
        delete [ ] pImgBuff;
        qDebug( ) << "GetJpegImage : Failed " << endl;
        return nRet;
    }
    // DS-40xxHC/HC+/HF/HCS JPEG4CIF(QCIF)
    // 4CIF 704¡Á576 QCIF 176¡Á144 CIF 352¡Á288
    // Save File

    QFile imgFile( strFile );
    if ( imgFile.open( QIODevice::WriteOnly ) ) {
        const char* pData = ( const char* ) pImgBuff;
        imgFile.write( pData, lSize );
        imgFile.close( );
    }

    delete [ ] pImgBuff;
    return nRet;
}
Exemplo n.º 2
0
LRESULT CMainDlg::OnCapturePicture(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
	unsigned long dwSize = 1920*1080*2;
	UCHAR* pJpegBuf = new UCHAR[dwSize];
	if(pJpegBuf == NULL)
	{
		return FALSE;
	}
	int iRet = GetJpegImage(m_channelHandle[(int)lParam], pJpegBuf, &dwSize, 100);
	if(iRet != 0)
	{
		delete pJpegBuf;
		MessageBox("fail to capture a Jpeg image!");
		return FALSE;
	}
	HANDLE hJpgFile = CreateFile("test.jpeg", GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hJpgFile == INVALID_HANDLE_VALUE)
	{
		delete pJpegBuf;
		MessageBox("fail to capture a Jpeg image!");
		return FALSE;          
	}
	if(!WriteFile(hJpgFile, pJpegBuf, dwSize, NULL, NULL))
	{
		delete pJpegBuf;
		CloseHandle(hJpgFile);
		MessageBox("fail to capture a Jpeg image!");
		return FALSE;          
	}
	delete pJpegBuf;
	CloseHandle(hJpgFile);

	return TRUE;
}