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

📄 cameracaptureengine.cpp

📁 SYMBIAN camera 样例程序如果需要了解更多或缺少什么文件可以邮件联系我
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                
        //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);//bmpDeviceSave 
        }
    else
        {
        fbsBitGc->DrawBitmap( TRect(iLandscapeSize), iBitmapSave );
        delete bmpDevice;
        }

    CleanupStack::PopAndDestroy(fbsBitGc);//fbsBitGc;

	// Start to save the image.
	AsyncStateChange(EStartToSaveImage);	
    }

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

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

    Return values: N/A

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

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

	void CCameraCaptureEngine::SetFocusRangeL()
	
	Description: Sets the autofocus range. 
                 Does nothing if AF is not supported

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::SetFocusRangeL( CCamAutoFocus::TAutoFocusRange aRange )
    {        
    // do nothing if AF not supported or focusing already in progress
    if( !iAutoFocus || iState == EFocusing )
        return;
        
    iAutoFocus->SetFocusRangeL( aRange );    
    iRange = aRange;
    
    // reset capture mode so the new range will be shown in UI
    iController.SetCaptureModeL( iCaptureSize, 
                                 (TInt)iFormat, 
                                 ETrue );    
    }

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

	void CCameraCaptureEngine::FocusRange( CCamAutoFocus::TAutoFocusRange& aRange )
	
	Description: Gets the current autofocus range. 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::FocusRange( CCamAutoFocus::TAutoFocusRange& aRange )
    {
    if( !iAutoFocus )
        return;

    iAutoFocus->FocusRange( aRange );
    }

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

	void CCameraCaptureEngine::StartFocusL()
	
	Description: Starts the optimised autofocus operation. 
                 Does nothing if AF is not supported

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::StartFocusL()
    {        
    // do nothing if AF not supported or focusing already in progress
    if( !iAutoFocus || iState == EFocusing)
        return;
        
    // if AF range is not defined, set to normal before first focus attempt
    if( !iRange )
        {
        iRange = CCamAutoFocus::ERangeNormal;
        iAutoFocus->SetFocusRangeL( iRange );
        }
        
        
    iState = EFocusing;
    iAutoFocus->AttemptOptimisedFocusL();            
    }
        


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

	void CCameraCaptureEngine::FocusCancel()
	
	Description: Cancels an ongoing autofocus operation

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::FocusCancel()
    {
    if(iAutoFocus && iState == EFocusing)
        {
        iState = EEngineIdle;
        iAutoFocus->Cancel();
        }
    }

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

	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:
            iEikEnv->HandleError( aError );
            reason = ECameraOverflow;
            break;
        case KErrInUse:
            reason = ECameraInUse;
			      iController.HandleError( aError );
            break;
        case KErrHardwareNotAvailable:
            iState = EEngineNoHardware;            
            reason = ECameraHwFailure;
            break;
        case KErrExtensionNotSupported:     // AF not supported
            reason = KErrNone;              
            iController.HandleError( aError );
            break;
        case KErrTimedOut:
            reason = ECameraOverflow;
            break;
        default:
            iEikEnv->HandleError( aError );
            reason = ECameraOverflow;
        }

    if ( reason )
        {
        if(iBitmapSave)
            iBitmapSave->Reset();
        delete iImageExif;
        iImageExif = 0;        
        }
    }

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

	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 EStartingViewFinder:
			    {
			    TRAPD( err, DoViewFinderL() );
                HandleError( err );
                if( err == KErrNone )
                    {
                    iState = EEngineIdle;
                    }
                break;
			    }
			case EStartToSaveImage:
				{
				iController.SaveImageL();
				break;
				}

			case EConvertingImage:
				{
				if( iFormat == CCamera::EFormatExif )     // EXIF file has been saved 
				    {                                     // - ok to discard image data		        
		        delete iImageExif;
		        iImageExif = 0;
		        }
		    else
				    DeleteEncoder();                      // release captured image file
				
				AsyncStateChange( EConverted );
				break;
				}

			case EConverted:			    
			    iController.ShowConversionStatusL( KImageSaved, ETrue );
				break;
				
		    default:
		        break;
			}
		}
    else
        __LOGSTR_TOFILE1("RunL called with Status: %d", iStatus.Int());
    }

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

	void CCameraCaptureEngine::AsyncStateChange(const TEngineState& aNextState)
	
	Description: Changes the engine state and completes an async request 
	             immediately
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::AsyncStateChange( const TEngineState& aNextState )
    {  
    TRequestStatus* status=(&iStatus); 
	iState = aNextState;	
	User::RequestComplete(status, KErrNone);
    SetActive();
    }


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

	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);
	}
	
	
/*
-----------------------------------------------------------------------------

	TBool CCameraCaptureEngine::IsViewFinderActive()

-----------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsViewFinderActive()
	{
	return iCamera->ViewFinderActive();
	}
	

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

	TBool CCameraCaptureEngine::IsAutoFocusSupported()

-----------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsAutoFocusSupported()
	{
	return ( iAutoFocus != 0 );
	}
	

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

    void CCameraCaptureEngine::ClientRectChangedL(TRect& aRect)
    
    Description: Notify the engine if the client rect size changes
    Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ClientRectChangedL(const TRect& aRect)
    {
    
    if( iLandscapeSize == aRect.Size() )
      {
      return;
      }
    // The given client rect size is the same as the landscape picture size      
    iLandscapeSize = aRect.Size();
        
    // In portrait mode the height is the same, but the width needs to be
    // calculated according to the aspect ratio
    iPortraitSize = TSize(
        (aRect.Size().iHeight * aRect.Size().iHeight / aRect.Size().iWidth), 
        aRect.Size().iHeight);

    delete iBitmapPortraitVF;
    iBitmapPortraitVF = new (ELeave) CWsBitmap( iEikEnv->WsSession() );
    User::LeaveIfError( iBitmapPortraitVF->Create( iPortraitSize, 
                                                   iDisplayMode ) );
     
    }
    
// end of file

⌨️ 快捷键说明

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