⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getpicturedlg.cpp

📁 佳能相机的照相程序和SDK库CDSDK71 WIN以及编程手册
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	
	if( m_hSource )
	{
		CDUnlockUI( m_hSource );
		CDCloseSource( m_hSource );
		m_hSource = NULL;
	}
	
}

void CGetPictureDlg::OnGetthumbnail() 
{
	// TODO: Add your control notification handler code here
	cdError			err;
	int				index;
	cdHImageItem	hImage;
	
	/* The handle of the item chosen is acquired. */
	index = m_CFile.GetCurSel();
	if( index==LB_ERR )
	{
		MessageBox( "The image is not chosen." );
		return;
	}
	hImage = (cdHImageItem)m_CFile.GetItemData( index );
	
	CString CFileName;
	m_CFile.GetText(index, CFileName);

	CFileDialog		CGetPath(	FALSE,
								NULL,
								CFileName,
								OFN_HIDEREADONLY | OFN_NONETWORKBUTTON | OFN_OVERWRITEPROMPT,
								"All Files (*.*)|*.*||",
								this );
	
	/* The path which saves a file is acquired. */
	if( CGetPath.DoModal() != IDOK )
	{
		return;
	}

	CString		CSavePath;
	CSavePath = CGetPath.GetPathName();
	
	/* UI is locked so that information may not be changed. */
	err = CDLockUI( m_hSource );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}
	
	cdHImageData	hImgData;
	cdStgMedium		MyMedium;
	char			szPath[MAX_PATH];
	
	/* Image data is acquired. */
	err = CDOpenImage( hImage );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}
	
	err = CDGetThumbnail( hImage, &hImgData );
	if( GETERRORID(err) != cdOK )
	{
		CDCloseImage( hImage );
		goto	camerr;
	}
	
	strcpy( szPath, CSavePath );
	MyMedium.Type = cdMEMTYPE_FILE;
	MyMedium.u.lpszFileName = szPath;
	
	err = CDGetImageData( hImgData, &MyMedium, NULL, NULL, 0 );
	if( GETERRORID(err) != cdOK )
	{
		CDCloseImage( hImage );
		goto	camerr;
	}
	
	err = CDCloseImage( hImage );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}
	
	/* The lock of UI is canceled. */
	err = CDUnlockUI( m_hSource );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}
	
	return;
	
camerr:
	char	szErrStr[256];
	
	wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
	MessageBox( szErrStr );
	
	CDUnlockUI( m_hSource );
	
}

void CGetPictureDlg::OnGetpicture() 
{
	// TODO: Add your control notification handler code here
	cdError			err;
	int				index;
	cdHImageItem	hImage;
	
	/* The handle of the item chosen is acquired. */
	index = m_CFile.GetCurSel();
	if( index==LB_ERR )
	{
		MessageBox( "The image is not chosen." );
		return;
	}
	hImage = (cdHImageItem)m_CFile.GetItemData( index );
	
	CString	CFileName;
	m_CFile.GetText(index, CFileName);
	
	CFileDialog		CGetPath(	FALSE,
								NULL,
								CFileName,
								OFN_HIDEREADONLY | OFN_NONETWORKBUTTON | OFN_OVERWRITEPROMPT,
								"All Files (*.*)|*.*||",
								this );
	
	
	/* The path which saves a file is acquired. */
	if( CGetPath.DoModal() != IDOK )
	{
		return;
	}
	CString	CSavePath;
	CSavePath = CGetPath.GetPathName();
	
	/* UI is locked so that information may not be changed. */
	err = CDLockUI( m_hSource );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}	
	
	cdHImageData	hImgData;
	cdStgMedium		MyMedium;
	char			szPath[MAX_PATH];
	
	/* Image data is acquired. */
	err = CDOpenImage( hImage );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}
	
	err = CDGetPicture( hImage, &hImgData );
	if( GETERRORID(err) != cdOK )
	{
		CDCloseImage( hImage );
		goto	camerr;
	}
	
	strcpy( szPath, CSavePath );
	MyMedium.Type = cdMEMTYPE_FILE;
	MyMedium.u.lpszFileName = szPath;
	
	err = CDGetImageData( hImgData, &MyMedium, NULL, NULL, 0 );
	if( GETERRORID(err) != cdOK )
	{
		CDCloseImage( hImage );
		goto	camerr;
	}
	
	err = CDCloseImage( hImage );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}
	
	/* The lock of UI is canceled. */
	err = CDUnlockUI( m_hSource );
	if( GETERRORID(err) != cdOK )
	{
		goto	camerr;
	}
	
	return;
	
camerr:
	char	szErrStr[256];
	
	wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
	MessageBox( szErrStr );
	CDUnlockUI( m_hSource );
	
}

void CGetPictureDlg::OnEnd() 
{
	// TODO: Add your control notification handler code here
	cdError	err;
		
	/* The lock of UI is canceled. */
	if( m_hSource )
	{
		if( m_hCallbackFunction )
		{
			/* The function which receives the event from a camera is canceled. */
			err = CDUnregisterEventCallbackFunction( m_hSource, m_hCallbackFunction );
			if( GETERRORID(err) != cdOK )
			{
				goto	camerr;
			}
			m_hCallbackFunction = NULL;
		}
		
		/* A device is closed. */
		err = CDCloseSource( m_hSource );
		if( GETERRORID(err) != cdOK )
		{
			goto	camerr;
		}
		
		m_hSource = NULL;
	}
	
	EndDialog( 0 );
	return;
	
camerr:
	char	szErrStr[256];
	
	wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
	MessageBox( szErrStr );
	
	if( m_hCallbackFunction )
	{
		CDUnregisterEventCallbackFunction( m_hSource, m_hCallbackFunction );
		m_hCallbackFunction = NULL;
	}
	CDCloseSource( m_hSource );
	m_hSource = NULL;
	
	EndDialog( 0 );
}

void CGetPictureDlg::OnDisconnect() 
{
	// TODO: Add your control notification handler code here
	cdError			err;
	
	m_CFile.ResetContent();
	
	if( m_hSource )
	{
		if( m_hCallbackFunction )
		{
			/* The function which receives the event from a camera is canceled. */
			err = CDUnregisterEventCallbackFunction( m_hSource, m_hCallbackFunction );
			if( GETERRORID(err) != cdOK )
			{
				goto	camerr;
			}
			m_hCallbackFunction = NULL;
		}
		
		/* A device is closed. */
		err = CDCloseSource( m_hSource );
		if( GETERRORID(err) != cdOK )
		{
			goto	camerr;
		}
		m_hSource = NULL;
	}
	
	m_CDisconnect.EnableWindow( FALSE );
	m_CThumbnail.EnableWindow( FALSE );
	m_CPicture.EnableWindow( FALSE );
	m_CConnect.EnableWindow( TRUE );
	
	return;
 
camerr:
	char	szErrStr[256];
	
	wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
	MessageBox( szErrStr );
	
}

void CGetPictureDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your control notification handler code here
	/* End processing of CDSDK is performed. */
	cdError		err;
	char		szErrStr[256];
	
	err = CDFinishSDK();
	if( GETERRORID(err) != cdOK )
	{
		wsprintf( szErrStr, "ErrorCode = 0x%08X", err );
		MessageBox( szErrStr );
	}
	
}


void CGetPictureDlg::OnquerySQL() 
{
	// TODO: Add your control notification handler code here
   ////zzy  ADOConn  kaoqusql;
	
   UpdateData(TRUE);
///	  kaoqusql=ADOConn.OnInitADOConn();
	::CoInitialize(NULL);

	HRESULT hr;
	::_ConnectionPtr m_pConnection;
	::_ConnectionPtr pConn;
    ::_RecordsetPtr m_pRecordset;  
	::_RecordsetPtr m_pRecordset_zp; 
	::_RecordsetPtr pRs;

	  hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象

	  
	if (FAILED(hr)) 
		{ 
			AfxMessageBox("Create Instance 失败!"); 
			return; 
		} 


_bstr_t strSRC; 
strSRC="Driver=SQL Server;Server="; 
strSRC+="192.168.2.58"; 
strSRC+=";Database="; 
strSRC+="kaoqu"; 
strSRC+=";UID=sa;PWD=kaishiyouwei"; 
strSRC+=""; 

hr = m_pConnection->Open(strSRC,"","",-1);


	if (FAILED(hr)) 
		{ 
			AfxMessageBox("连接数据库 失败!"); 
			return; 
		} 

_bstr_t strfileid="512001000001116";	
_bstr_t bstrSQL="select * from fileinfo where fileid='"+strfileid+"'";
   //连接数据库,如果connection对象为空,则重新连接数据库

   //创建记录集对象
   m_pRecordset.CreateInstance(_uuidof(Recordset));
   m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
   m_pRecordset->MoveFirst();

   m_fileid=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("FileID");
   m_ID_card=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID_card");
   m_fullname=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("fullname");
   m_ID_card=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID_card");
   m_address=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("address");
   m_phone=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("phone");
   m_sex=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("sex");
 //  m_=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("");

m_pRecordset->Close(); 


   //_bstr_t bstrSQL_zp="select * from images_del where id=252";
   _bstr_t bstrSQL_zp="select * from ExamineePhoto  where fileid='"+strfileid+"'";
    //  _bstr_t bstrSQL_zp="select * from images_del ";
      m_pRecordset_zp.CreateInstance(_uuidof(Recordset));
   m_pRecordset_zp->Open(bstrSQL_zp,_variant_t((IDispatch *)m_pConnection,true),adOpenKeyset,adLockOptimistic,adCmdText); 

   	
	  //Load   imgs   

  
  variant_t   vImg;   
  VariantInit(&vImg);   
  m_pRecordset_zp->MoveFirst();   

  //start   load   images   data   

  DWORD   dwSize;   
  dwSize=m_pRecordset_zp->GetFields()->GetItem("Photo")->GetActualSize();   
  vImg=m_pRecordset_zp->GetFields()->GetItem("Photo")->GetChunk(dwSize);   
  char   *pBuff;   
  if(vImg.vt   ==   (VT_ARRAY   |   VT_UI1))                                                                   ///判断数据类型是否正确   
  {   
  //I   dont   know   why   this   gets   error,I   can   not   access   the   buffer   
  SafeArrayAccessData(vImg.parray,(void   **)&pBuff);                             ///得到指向数据的指针   
  int   err=::GetLastError();   
  CFile   f;   
  f.Open   ("C:\\"+strfileid+".jpg",CFile::modeWrite|CFile::modeCreate   );   
  f.Write   (pBuff,dwSize);   
  f.Close   ();   
  SafeArrayUnaccessData   (vImg.parray);   
    
  }   

   CString sPath;
   _bstr_t strpath;

	 CDC* pDC = GetDlgItem(IDC_zpsql)->GetDC();

    strpath="C:\\"+strfileid+".jpg";
   // sPath=_T(strpath);

	 sPath = (LPCSTR)strpath;
//	 sPath=_T("C:\\512001000001115.jpg");

    ShowJpgGif(pDC,sPath,0,0);

   UpdateData(FALSE);


} 









void CGetPictureDlg::OnOpenCamera() 
{
	// TODO: Add your control notification handler code here
	//WinExec("notepad.exe f:\\调用程序.txt",SW_SHOW);
	WinExec("D:\\RELCTRL\\Release\\RelCtrl.exe",SW_SHOW);
	
}


void CGetPictureDlg::Ondrawnew() 
{
	// TODO: Add your control notification handler code here
  CDC*pDC;   
     pDC=GetDC();   

::CoInitialize(NULL); // COM 初始化 
HRESULT hr; 
CFile file; 

file.Open( "D:\\RELCTRL\\Release\\FV000001.JPG ", CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容 
DWORD dwSize = file.GetLength(); 
HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize ); 
LPVOID lpBuf = ::GlobalLock( hMem ); 
file.ReadHuge( lpBuf, dwSize ); 
file.Close(); 
::GlobalUnlock( hMem ); 

IStream * pStream = NULL; 
IPicture * pPicture = NULL; 

// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存 
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream ); 
ASSERT ( SUCCEEDED(hr) ); 

hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture ); 
ASSERT(hr==S_OK); 

long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米 
pPicture->get_Width( &nWidth ); // 宽 
pPicture->get_Height( &nHeight ); // 高 

////////原大显示////// 
// CSize sz( nWidth,nHeight ); 

//按比例压缩显示
double xbili=0.2;
double ybili=0.2;

CSize sz( int(nWidth*xbili),int( nHeight*ybili) ); 
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位 
//pPicture->Render(pDC->m_hDC,0,0,sz.cx,sz.cy, 0,nHeight,nWidth,-nHeight,NULL); 

pPicture->Render(pDC->m_hDC,430,150,sz.cx,sz.cy, 0,nHeight,nWidth,-nHeight,NULL); 

////////按窗口尺寸显示//////// 
// CRect rect; GetClientRect(&rect); 
// pPicture->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(), 
// 0,nHeight,nWidth,-nHeight,NULL); 

if ( pPicture ) pPicture->Release();// 释放 IPicture 指针 
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem 

::CoUninitialize(); 
}










void CGetPictureDlg::OnBaoCunZP() 
{
	// TODO: Add your control notification handler code here
   UpdateData(TRUE);
///	  kaoqusql=ADOConn.OnInitADOConn();
	::CoInitialize(NULL);

	HRESULT hr;
	::_ConnectionPtr m_pConnection;

	::_RecordsetPtr m_pRecordset_zp; 

	  hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象

	  
	if (FAILED(hr)) 
		{ 
			AfxMessageBox("Create Instance 失败!"); 
			return; 
		} 


_bstr_t strSRC; 
strSRC="Driver=SQL Server;Server="; 
strSRC+="192.168.2.58"; 
strSRC+=";Database="; 
strSRC+="kaoqu"; 
strSRC+=";UID=sa;PWD=kaishiyouwei"; 
strSRC+=""; 

hr = m_pConnection->Open(strSRC,"","",-1);


	if (FAILED(hr)) 
		{ 
			AfxMessageBox("连接数据库 失败!"); 
			return; 
		} 


   _bstr_t strfileid="512001000001116";	
   _bstr_t bstrSQL_zp="select * from ExamineePhoto  where fileid='"+strfileid+"'";
   m_pRecordset_zp.CreateInstance(_uuidof(Recordset));
   m_pRecordset_zp->Open(bstrSQL_zp,_variant_t((IDispatch *)m_pConnection,true),adOpenKeyset,adLockOptimistic,adCmdText); 

   
   //连接数据库,如果connection对象为空,则重新连接数据库

  /*先查出记录来*/   
 //// strSql.Format   ("SELECT   ID_,PERSON_ID_,SEQ_,IMG_   FROM   X_IMAGE   WHERE   PERSON_ID_=%d  ORDER   BY   SEQ_   ASC",personData->m_id);   
  //...   
 /// dbData.rets ->Open   ((LPCTSTR)strSql,dbData.conn.GetInterfacePtr   (),adOpenDynamic,adLockOptimistic,adCmdText);   
  /*然后准备图片数据*/   

  VARIANT   vImg;   
  char   *pBuff,*pBuffFile;   
  //...   
  /*从文件读BMP图像*/   
  CFile   f;   
  DWORD   dwSize;   
  
  if(f.Open   ("C:\\"+strfileid+".jpg",CFile::modeRead   |CFile::modeNoTruncate   )   &&   (dwSize=f.GetLength   ())>10)//打开文件   
  {   
	  
  pBuffFile=new   char[dwSize];   
  f.Read   (pBuffFile,dwSize);//读出来   
  VariantInit(&vImg);//初始化变量   
  vImg.vt   =VT_ARRAY   |   VT_UI1;//设置数据类型   
  SAFEARRAYBOUND   rgsabound[1];//创建SAFEARRAY必须的   

  rgsabound[0].lLbound   =   0;   
  rgsabound[0].cElements   =   dwSize;//数据大小   
  vImg.parray     =   SafeArrayCreate(VT_UI1,   1,   rgsabound);       ///创建SAFEARRAY对象   
  
  SafeArrayAccessData(vImg.parray,(void   **)&pBuff);//获取SAFEARRAY的缓冲区指针   
  memcpy(pBuff,pBuffFile,dwSize);//把图片数据COPY进去   
  ::SafeArrayUnaccessData   (vImg.parray   );//释放SAFEARRAY的缓冲区指针   
  //到这里已经把图片封装进了vImg了   
  //然后把vImg存到数据库里面去   
  m_pRecordset_zp->MoveLast();//根据定需要定位记录   

  m_pRecordset_zp->GetFields()->GetItem("photo")->AppendChunk(vImg);//把vImg放到recordset的IMG_字段,这个字段是SQLSERVER的IMAGE数据类型   


 m_pRecordset_zp->Update();//更新   

   
  m_pRecordset_zp->Close();//关闭Recordset  

	
  }
}


void CGetPictureDlg::OnButton1() 
{

	CString sPath;
	// TODO: Add your control notification handler code here
    CDC* pDC = GetDlgItem(IDC_zp)->GetDC();

   // strpath="C:\\"+strfileid+".jpg";
   // sPath=_T(strpath);

//	 sPath = (LPCSTR)strpath;
	 sPath=_T("C:\\512001000001115.jpg");

    ShowJpgGif(pDC,sPath,0,0);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -