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

📄 cameracaptureengine.cpp

📁 SYMBIAN camera 样例程序如果需要了解更多或缺少什么文件可以邮件联系我
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    __LOGSTR_TOFILE1("Saving image %S", aNewFilePathAndName);
    
    if( iFormat == CCamera::EFormatExif )
        {        
        TInt fErr = iFile.Replace( *aFs, *aNewFilePathAndName, EFileWrite );
        if (fErr == KErrNone)
            {
            iState = EConvertingImage; // no need for actual conversion step
                                       // when capturing to EXIF JPEG
            iFile.Write( *iImageExif, iStatus );
            SetActive();
            return;
            }
        }
        
    if ( !iEncoder )
        {
        if ( aFs && aNewFilePathAndName )
            {
            iEncoder = CImageEncoder::FileNewL(*aFs, *aNewFilePathAndName, 
                KMimeType);
            }
        else
            {
            User::Leave( KErrArgument );
            }
	}

	// If it is not busy, start to do the conversion.
	if ( !IsActive() )
		{
		iEncoder->Convert( &iStatus, *iBitmapSave );
		iState = EConvertingImage;

		// Update the status pane to "Saving image..."
		iController.ShowConversionStatusL( KSavingImage );
		SetActive();
		}
    }

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

	void CCameraCaptureEngine::ReserveCameraL()

	Description: Reserves camera
	Comments   : "ResereComplete" will get called after completion

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ReserveCameraL()
    {
    iStart = ETrue;
    //Ongoing, no need to issue again
    if ( iCameraReserved && !iCameraReserveComplete )
        {
        User::Leave(0);
        }

    if ( !iCameraReserved && iCameraReserveComplete )
        {
        iCameraReserved = ETrue;
        iCameraReserveComplete = EFalse;
        iCamera->Reserve(); //Async
        }

    if ( iCameraReserved && iCameraReserveComplete )
        {
        if( iCapturePrepared && !iCamera->ViewFinderActive() )
            {
            __LOGSTR_TOFILE("Restarting viewfinder");
            iCamera->StartViewFinderBitmapsL( iLandscapeSize );
            iState = EEngineIdle;
            }
        else if ( !iPowering )
            {
            iPowering = ETrue;
            iCamera->PowerOn();
            }
        else
            {            
            User::Leave(0);
            }
        }
    }

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

	void CCameraCaptureEngine::ReleaseCamera()

	Description: Releases camera
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ReleaseCamera()
    {
    iStart = EFalse;  
    if ( iCameraReserved && iCameraReserveComplete )
        {
        if(iAutoFocus)
            {
            // bring AF subsystem to idle 
            TRAPD( ignore, iAutoFocus->ResetToIdleL() );
            iAutoFocus->Close();
            }
        iCamera->Release();
        iCameraReserved = EFalse; 
        }
    
    iCapturePrepared = EFalse;
    iState = EEngineNotReady;
    }

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

	void CCameraCaptureEngine::PowerOff()

	Description: Switches off camera power 
	Comments   : 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::PowerOff()
    {
    if ( !iPowering && iCameraReserved )
        {
        iCamera->PowerOff();
        ReleaseCamera();
        }
    }

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

	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
        {   
        // try to init the AF control - not fatal if fails                     
        if( iAutoFocus )
            {
            TRAPD( afErr, iAutoFocus->InitL( *this ) );
            if(afErr)
                {
                HandleError( KErrExtensionNotSupported );
                delete iAutoFocus;
                iAutoFocus = 0;
                }
            }
            
        // start viewfinder
        AsyncStateChange(EStartingViewFinder);
        }
    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)
    {
    __LOGSTR_TOFILE1("ImageReady: %d", aError);
    TInt err(KErrNone);
    
    if ( aError == KErrNone )
        {
        if( iFormat == CCamera::EFormatExif )
            {
            if ( iImageExif )
                {
                delete iImageExif;
                iImageExif = 0;
                }
            iImageExif = aData->Alloc();
            // TODO: Post-exposure drawing for images 
            // captured directly in EXIF JPEG format
            AsyncStateChange(EStartToSaveImage);
            }
        else
            {
            iBitmapSave->Reset();
            if( aBitmap )
                {
                err = iBitmapSave->Duplicate( aBitmap->Handle() );
                if( err == KErrNone )
                    {
                    TRAP(err, DrawL()); // draw post-exposure image
                    }
                HandleError( err );
                }
            }
        }
    else
        {
        HandleError( aError );  
        }
    }
    

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

	void CCameraCaptureEngine::InitComplete( TInt aError )

	Description: called when initalising autofocus is ready 

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::InitComplete( TInt aError )
    {
    __LOGSTR_TOFILE1("InitComplete: %d", aError);
    // TODO: Error handling   
    }
    
    
/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::OptimisedFocusComplete( TInt aError )

	Description: called when camera has optimised focus

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::OptimisedFocusComplete( TInt aError )
    {
    __LOGSTR_TOFILE1("OptimisedFocusComplete: %d", aError);
    iState = EEngineIdle;
    
    if(!aError)
        iController.PlaySound(ESoundIdFocused);    
    }
    

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

	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*/)
    {
    // We are not using video capture
    }

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

	void CCameraCaptureEngine::ClipL(const CFbsBitmap& aFrame)

	Description: Clips 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-iPortraitSize.iWidth)/2;
    TInt x2 = x1+iPortraitSize.iWidth;
    TInt y1 = (size.iHeight-iPortraitSize.iHeight)/2;
    TInt y2 = y1+iPortraitSize.iHeight;

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

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

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

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

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

    Return values: portrait size

-----------------------------------------------------------------------------
*/
TRect CCameraCaptureEngine::Portrait( const CFbsBitmap* aBitmap)
    {
    TRect portrait = TRect();
    if ( aBitmap )
        {
        TSize size = aBitmap->SizeInPixels();
        TInt portx = 
            iPortraitSize.iWidth * size.iWidth / iLandscapeSize.iWidth;
        TInt porty = 
            iPortraitSize.iHeight * size.iHeight / iLandscapeSize.iHeight;
        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;

⌨️ 快捷键说明

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