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

📄 cameracaptureengine.cpp

📁 S60官方摄像头程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	void CCameraCaptureEngine::ReserveComplete(TInt aError)

	Description: reserve completes
	Comments   : Symbian Onboard Camera API observer, This happens after 
				 CCamera::Reserve() is called

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ReserveComplete(TInt aError)
    {
    iCameraReserveComplete = ETrue;
    if ( aError )
        {
        iCameraReserved = EFalse;
        HandleError( aError );
        }
    
    if ( iStart )
        {
        iPowering = ETrue;
        iCamera->PowerOn();
        }
    else
        {
        ReleaseCamera();
        }
    }

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

	void CCameraCaptureEngine::PowerOnComplete(TInt aError)

	Description: poweron completes
	Comments   : Symbian Onboard Camera API observer, This happens after 
				 CCamera::PowerOn() is called

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::PowerOnComplete(TInt aError)
    {
    HandleError( aError );
    iPowering = EFalse;
    if ( iStart )//The Operation is not cancelled
        {
        TRAPD( err, DoViewFinderL() );
        HandleError( err );
        }
    else
        {
        ReleaseCamera();
        }
    }

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

	void CCameraCaptureEngine::ViewFinderFrameReady(CFbsBitmap& aFrame)

	Description: Switches off camera power 
	Comments   : Symbian Onboard Camera API observer,  This is called once 
				"StartViewFinderBitmapsL" is called

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ViewFinderFrameReady(CFbsBitmap& aFrame)
    {
    if ( iController.CameraMode() == ECameraPortraitMode )
        {
        TRAPD(ignore, ClipL(aFrame));
        iController.ViewFinding( *iBitmapPortraitVF );
        }
    else
        {
		// Pass the Bitmap frame to the controller
        iController.ViewFinding( aFrame );
        }
    }

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

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

	Description: called when an image is ready 
	Comments   : Symbian Onboard Camera API observer,  This is called once 
				"CCamera::CaptureImage()" is called

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,
									  TInt aError)
    {
    TInt err(KErrNone);
    if ( !aError )
        {
        iBitmapSave = aBitmap;
        TRAP(err, DrawL());
        HandleError( err );
        }
    else
        {
        HandleError( aError );  
        }
    }

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

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

	Description: called when a framebuffer is ready. 
	Comments   : Symbian Onboard Camera API observer,  This is called once 
				"CCamera::StartVideoCapture()" is called

    Return values: N/A

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

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

	void CCameraCaptureEngine::ClipL(const CFbsBitmap& aFrame)

	Description: Cli[s the viewfinding iamges according to portrait mode size
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ClipL(const CFbsBitmap& aFrame)
    {
    TSize size = aFrame.SizeInPixels();
    TInt x1 = (size.iWidth-KPortraitImageWidth)/2;
    TInt x2 = x1+KPortraitImageWidth;
    TInt y1 = (size.iHeight-KPortraitImageHeight)/2;
    TInt y2 = y1+KPortraitImageHeight;

    CFbsBitGc* fbsBitGc = CFbsBitGc::NewL(); //graphic context
    CleanupStack::PushL( fbsBitGc );
    CFbsBitmapDevice* portraitImageDevice = CFbsBitmapDevice::NewL( iBitmapPortraitVF );
    fbsBitGc->Activate( portraitImageDevice );

    fbsBitGc->BitBlt( TPoint(0,0), &aFrame, TRect(x1,y1,x2,y2) );

    delete portraitImageDevice;
    CleanupStack::PopAndDestroy();//fbsBitGc;
        
    }

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

	static TRect Portrait( const CFbsBitmap* aBitmap)
	
	Description: Calculates Portrait image size from bigger snapped image 
				 remaining the aspect
	Comments   : 

    Return values: portrait size

-----------------------------------------------------------------------------
*/
static TRect Portrait( const CFbsBitmap* aBitmap)
    {
    TRect portrait = TRect();
    if ( aBitmap )
        {
        TSize size = aBitmap->SizeInPixels();
        TInt portx = KPortraitImageWidth * size.iWidth/KLandscapeImageWidth;
        TInt porty = KPortraitImageHeight * size.iHeight/KLandscapeImageHeight;
        TInt x1 = (size.iWidth-portx)/2;
        TInt x2 = x1+portx;
        TInt y1 = (size.iHeight-porty)/2;
        TInt y2 = y1+porty;
        portrait.SetRect(x1,y1,x2,y2);
        }
    return portrait;
    }

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

	void CCameraCaptureEngine::DrawL()
	
	Description: Draws captured image on the screen, modifies if needed
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::DrawL()
    {
    CFbsBitGc* fbsBitGc = CFbsBitGc::NewL(); //graphic context
    CleanupStack::PushL( fbsBitGc );
    if ( iController.CameraMode() == ECameraPortraitMode )
        {		
        User::LeaveIfError( iController.GetSnappedImage().Resize( iPortraitSize ));
        }
    else
        {
        User::LeaveIfError( iController.GetSnappedImage().Resize( iLandscapeSize ));
        }

    CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL( &iController.GetSnappedImage() );	
    fbsBitGc->Activate( bmpDevice );

    if ( iController.CameraMode() == ECameraPortraitMode )
        {
        TRect portraitRect = Portrait( iBitmapSave );
        //Shrink to snap image size
        fbsBitGc->DrawBitmap( TRect(iPortraitSize), iBitmapSave, portraitRect );
        delete bmpDevice;
                
        //Full color image
        CFbsBitmapDevice* bmpDeviceSave = CFbsBitmapDevice::NewL( iBitmapSave );
        CleanupStack::PushL( bmpDeviceSave );
        fbsBitGc->Activate( bmpDeviceSave );
        fbsBitGc->DrawBitmap( TRect(iPortraitSize), iBitmapSave, portraitRect );
        //To be saved
        User::LeaveIfError( iBitmapSave->Resize( iPortraitSize ));  
        CleanupStack::PopAndDestroy();//bmpDeviceSave 
        }
    else
        {
        fbsBitGc->DrawBitmap( TRect(iLandscapeSize), iBitmapSave );
        delete bmpDevice;
        }

    CleanupStack::PopAndDestroy();//fbsBitGc;

	// Start to save the image.
	StartToSaveImage();	
    }

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

	TInt CCameraCaptureEngine::SetZoomFactorL(TBool aEnable) 
	
	Description: Sets zoom on/off
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
TInt CCameraCaptureEngine::SetZoomFactorL(TBool aEnable) 
    {   
    TInt bitmapCount = ECameraZoomLimit - ECameraZoom2Uid;  
    if ( iInfo.iMaxZoomFactor != 0 && iInfo.iMaxZoomFactor != 1 )//both 0 and 1 indicate that 
                                                                 //zoom functionality is not supported      
        {
        if ( aEnable && iZoomFactor < iInfo.iMaxZoom )
            {
            iZoomFactor++;
            }
        if ( !aEnable && iZoomFactor > iInfo.iMinZoom )
            {
            iZoomFactor--;
            }
        iCamera->SetZoomFactorL( iZoomFactor );
        return ( iInfo.iMaxZoom > bitmapCount )?KErrNotFound:iZoomFactor-1;//Zoom ind. bitmap offset 
        }
    if ( iInfo.iMaxDigitalZoomFactor != 0 && iInfo.iMaxDigitalZoomFactor != 1 )
        {
        if ( aEnable && iZoomFactor < iInfo.iMaxDigitalZoom )
            {
            iZoomFactor++;
            }
        if ( !aEnable && iZoomFactor > 0 )
            {
            iZoomFactor--;
            }
        iCamera->SetDigitalZoomFactorL(iZoomFactor);
        iCapturePrepared = EFalse;
        return ( iInfo.iMaxDigitalZoom > bitmapCount )?KErrNotFound:iZoomFactor-1;//Zoom ind. bitmap offset 
        }
    return KErrNotFound; 
    }

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

	void CCameraCaptureEngine::HandleError(TInt aError )
	
	Description: Displays error message
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::HandleError(TInt aError )
    {
    TInt reason(KErrNone);
    switch( aError )
        {
        case KErrNone:
            reason = KErrNone;
            break;
        case KErrNoMemory:
            CEikonEnv::Static()->HandleError( aError );
            reason = ECameraOverflow;
            break;
        case KErrInUse:
            reason = ECameraInUse;
			iController.HandleError( aError );
            break;
        case KErrHardwareNotAvailable:
            reason = ECameraHwFailure;
            break;
        case KErrTimedOut:
            reason = ECameraOverflow;
            break;
        default:
            CEikonEnv::Static()->HandleError( aError );
            reason = ECameraOverflow;
        }

    if ( reason )
        {  
        delete iBitmapSave;
        iBitmapSave = NULL;		
        }
    }

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

	void CCameraCaptureEngine::DoCancel()    
	
	Description: Cancels the Active object
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::DoCancel()    
    {
	if ( iState == EConvertingImage )
		{
		iEncoder->Cancel();
		DeleteEncoder();
		}
    }

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

	void CCameraCaptureEngine::RunL()
	
	Description: called when an asynchronous request is completed
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::RunL()
    {   
	if ( iStatus == KErrNone )
		{
		switch ( iState )
			{
			case EStartToSaveImage:
				{
				iController.SaveImageL();
				break;
				}

			case EConvertingImage:
				{
				DeleteEncoder(); //Release captured image file
				// Shows the status to "Image saved"
				_LIT( KImageSaved, "Image saved" );
				iState = EConverted;
				iController.ShowConversionStatusL( KImageSaved );
				break;
				}

			default:
				break;
			}
		}
    }

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

	void CCameraCaptureEngine::StartToSaveImage()
	
	Description: initiates a request to start to save an image
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::StartToSaveImage()
    {  
    TRequestStatus* status=(&iStatus); 
	iState = EStartToSaveImage;	
    SetActive();

    User::RequestComplete(status, KErrNone);
    }


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

	TBool CCameraCaptureEngine::IsImageConversionInProgress()
	
	Description: returns whether the image conversion is in progress or not
	Comments   : 

    Return values: true if it is in progress

-----------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsImageConversionInProgress()
	{
	return ( iState == EConvertingImage || iState == EStartToSaveImage );
	}

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

	TEngineState CCameraCaptureEngine::GetEngineState()
	
	Description: get the engine state
	Comments   : 

    Return values: return engine state

-----------------------------------------------------------------------------
*/
TEngineState CCameraCaptureEngine::GetEngineState()
	{
	return iState;
	}

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

	void CCameraCaptureEngine::SetEngineState( TEngineState aState )
	
	Description: set the engine state
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::SetEngineState( TEngineState aState )
	{
	iState = aState;
	}

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

	TBool CCameraCaptureEngine::IsCameraUsedByAnotherApp()
	
	Description: return whether the camera is being used another app.
	Comments   : 

    Return values: true if it is used by another app.

-----------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsCameraUsedByAnotherApp()
	{
	return (!iCameraReserved);
	}

⌨️ 快捷键说明

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