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

📄 videoviewfinder.cpp

📁 nokia S60_video_operation
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CVideoViewFinder from VideoViewFinder.h
*  Part of  : Video Recording Example (VRex)
*  Created  : 16.03.2004 by Nokia Forum
*  Description: Declares the video view finder control
*
*  Version  :
*  Copyright: Nokia Corporation
* ============================================================================
*/
#include    "VideoViewFinder.h"

#include <eikenv.h> // CEikonEnv

/*
-----------------------------------------------------------------------------

	CVideoViewFinder::CVideoViewFinder()

	Description: C++ default constructor can NOT contain any code, that
				 might leave.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CVideoViewFinder::CVideoViewFinder()
	: iState(EFinderInactive)
    {
    }

/*
-----------------------------------------------------------------------------

	CVideoViewFinder::~CVideoViewFinder()

	Description: Destructor.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CVideoViewFinder::~CVideoViewFinder()
    {
    if(iCamera)
	    {
	    Stop();
	    delete iCamera;
	    iCamera = NULL;
	    }
    }

/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::ConstructL(TInt aCameraHandle)

	Description: Second phase constructor.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoViewFinder::ConstructL(TInt aCameraHandle)
	{	
	iCamera = CCamera::NewL(*this, aCameraHandle);
	}
	
/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::StartL()

	Description: This method starts video view finder.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/	
void CVideoViewFinder::StartL()
	{
	if(!iCamera) 
		{
		User::Leave(KErrNotReady);
		}
	
	iState = EFinderInitializing;	
	iCamera->Reserve();
	
	ActivateL();
	DrawDeferred();
	}

/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::Stop()

	Description: This method stops video view finder.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/		
void CVideoViewFinder::Stop()
	{
	if(iState==EFinderActive)
		{
		iCamera->PowerOff();
		iCamera->Release();
		}
	iState = EFinderInactive;
	}
	
/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::ReserveComplete(TInt aError)

	Description: This method informs that camera reservation is complete.
	Comments   : Called asynchronously when CCamera::Reserve() completes. 

    Return values: N/A

-----------------------------------------------------------------------------
*/		
void CVideoViewFinder::ReserveComplete(TInt aError) 
	{
	if(aError==KErrNone)
		{		
		iCamera->PowerOn();	
		}
	else
		{		
		iState = EFinderFailed;
		}
	}

/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::PowerOnComplete(TInt aError)

	Description: This method indicates camera power on is complete.
	Comments   : Called on completion of CCamera:PowerOn().

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoViewFinder::PowerOnComplete(TInt aError) 
	{
	if(aError==KErrNone)
		{
		TSize finderSize = Size();
		// Start view finder. On return, finderSize contains the finder size
		iCamera->StartViewFinderBitmapsL(finderSize);	
		
		TRect rect = Rect();
		
		// Calculate position for finder bitmaps (centered on component)
		// iFinderPosition is the top-left coordinate for bitmap
		iFinderPosition = rect.iTl;
		iFinderPosition.iX += (rect.Size().iWidth - finderSize.iWidth)/2;
		iFinderPosition.iY += (rect.Size().iHeight - finderSize.iHeight)/2;		

		iState = EFinderActive;
		}
	else
		{
		iCamera->Release();
		iState = EFinderFailed;
		}
	}
	
/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::ViewFinderFrameReady(CFbsBitmap& aFrame)

	Description: This method tests whether transfer of view finder data has completed.
	Comments   : Called periodically in response to the use of 
				 CCamera::StartViewFinderBitmapsL().

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CVideoViewFinder::ViewFinderFrameReady(CFbsBitmap& aFrame) 
	{	
	// Keep backlight on while finder is active
    User::ResetInactivityTime();
  
  	// Get graphics context
    CWindowGc &gc = SystemGc();        
    
    // Graphics context must be activated, because we are not in Draw()
	gc.Activate(Window());
	
	// Draw finder frame to screen; BitBlt is much faster than DrawBitmap
	gc.BitBlt(iFinderPosition, &aFrame);
	
	// Deactivate graphics context
    gc.Deactivate();
	}

/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::ImageReady(CFbsBitmap* aBitmap, HBufC8* aData, TInt aError) 

	Description: This method transfers the current image from the camera to the client.
	Comments   : Called asynchronously when CCamera::CaptureImage() completes.

    Return values: N/A

-----------------------------------------------------------------------------
*/	
void CVideoViewFinder::ImageReady(CFbsBitmap* /*aBitmap*/, HBufC8* /*aData*/, TInt /*aError*/) 
	{
	}

/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::FrameBufferReady(MFrameBuffer* aFrameBuffer, TInt aError) 

	Description: This method passes a filled frame buffer to the client.
	Comments   : Called asynchronously, when a buffer has been filled with the 
				 required number of video frames by CCamera::StartVideoCapture().

    Return values: N/A

-----------------------------------------------------------------------------
*/	
void CVideoViewFinder::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/, TInt /*aError*/) 
	{
	}

/*
-----------------------------------------------------------------------------

	void CVideoViewFinder::Draw(const TRect& aRect) const

	Description: This method is called by the framework, draws the view.
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/	
void CVideoViewFinder::Draw(const TRect& aRect) const
    {
    // Draw the background of finder
    CWindowGc &gc = SystemGc(); 
        
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);      
   	gc.SetBrushColor(KRgbWhite);
		
	gc.DrawRect(aRect);			
    }	
    
/*
-----------------------------------------------------------------------------

	CVideoViewFinder::TFinderState CVideoViewFinder::State() const

	Description: This method returns the state of video view finder.
	Comments   : 

    Return values: Video view finder state
     
-----------------------------------------------------------------------------
*/    
CVideoViewFinder::TFinderState CVideoViewFinder::State() const
	{
	return iState;
	}
	
/*
-----------------------------------------------------------------------------

	TInt CVideoViewFinder::CameraHandle()

	Description: This method returns camera handle.
	Comments   : 

    Return values: Handle to camera object

-----------------------------------------------------------------------------
*/
TInt CVideoViewFinder::CameraHandle()
	{
	return iCamera->Handle();
	}

⌨️ 快捷键说明

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