Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

源代码

From Wiki
Jump to: navigation, search
Article Metadata

文章
User:Jiangbaolan 在 01 Apr 2009 创建
最后由 hamishwillee 在 06 Mar 2012 编辑
ifndef __CCAMERAENGINE_H_
#define __CCAMERAENGINE_H_
 
#include <ECam.h> // CCamera, MCameraObserver
 
#include "Camera.hrh"
 
class CCameraEngine : public MCameraObserver
{
public: // Constructors and destructor
/**
* Two-phased constructor.
*/

static CCameraEngine* NewL();
 
/**
* Destructor.
*/

virtual ~CCameraEngine();
 
private: // Constructors and destructor
/**
* Symbian OS default constructor.
*/

CCameraEngine();
 
/**
* Symbian OS constructor.
*/

void ConstructL();
 
private: // Methods from base classes
/**
* From MCameraObserver.
* Gets called when CCamera::Reserve() is completed.
*/

virtual void ReserveComplete(TInt aError);
 
/**
* From MCameraObserver.
* Gets called when CCamera::PowerOn() is completed.
*/

virtual void PowerOnComplete(TInt aError);
 
/**
* From MCameraObserver.
* Gets called when CCamera::StartViewFinderBitmapsL() is completed.
*/

virtual void ViewFinderFrameReady(CFbsBitmap& aFrame);
 
/**
* From MCameraObserver.
* Gets called when CCamera::CaptureImage() is completed.
*/

virtual void ImageReady(CFbsBitmap* aBitmap,
HBufC8* aData, TInt aError);
 
/**
* From MCameraObserver.
* Gets called when CCamera::StartVideoCapture() is completed.
*/

virtual void FrameBufferReady(MFrameBuffer* aFrameBuffer,
TInt aError);
 
public: // New Functions
/**
* Takes a picture.
*/

void SnapL();
 
/**
* Reserves the camera.
*/

void ReserveCameraL();
 
private: // Data
CCamera* iCamera;
TEngineState iState;
};
 
#endif /*__CCAMERAENGINE_H_*/源文件 CCameraEngine.cpp
#include "Camera.hrh"
#include "CCameraEngine.h"
 
/*
-------------------------------------------------------------------------------
Two-phased constructor
-------------------------------------------------------------------------------
*/

CCameraEngine* CCameraEngine::NewL()
{
CCameraEngine* self = new (ELeave) CCameraEngine();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
 
/*
-------------------------------------------------------------------------------
Destructor. Frees allocated resources.
-------------------------------------------------------------------------------
*/

CCameraEngine::~CCameraEngine()
{
delete iCamera;
}
 
/*
-------------------------------------------------------------------------------
C++ default constructor
-------------------------------------------------------------------------------
*/

CCameraEngine::CCameraEngine()
{
iState = EEngineNotReady;
}
 
/*
-------------------------------------------------------------------------------
Symbian OS 2nd phase constructor
-------------------------------------------------------------------------------
*/

void CCameraEngine::ConstructL()
{
// TODO: It is assumed here that the device has a camera.
// Add error handling, if this may not be the case.
 
// Camera index 0 is the main camera
iCamera = CCamera::NewL(*this, 0);
}
 
/*
-------------------------------------------------------------------------------
Reserves the camera.
-------------------------------------------------------------------------------
*/

void CCameraEngine::ReserveCameraL()
{
iCamera->Reserve();
 
// On completion, MCameraObserver::ReserveComplete() will be called
}
 
/*
-------------------------------------------------------------------------------
Symbian Onboard Camera API observer. Gets called after CCamera::Reserve() is
called.
-------------------------------------------------------------------------------
*/

void CCameraEngine::ReserveComplete(TInt aError)
{
// TODO: Error handling
 
iState = ECameraReserved;
iCamera->PowerOn();
}
 
/*
-------------------------------------------------------------------------------
Symbian Onboard Camera API observer. Gets called after CCamera::PowerOn() is
called.
-------------------------------------------------------------------------------
*/

void CCameraEngine::PowerOnComplete(TInt aError)
{
// TODO: Error handling
 
// Prepare the capture. It is assumed here that the device supports
// capturing in EXIF JPEG format.
CCamera::TFormat format = CCamera::EFormatExif;
const TInt KImageSizeIndex = 1; // 2nd largest image size
iCamera->PrepareImageCaptureL(format, KImageSizeIndex);
 
// Everything is ready. Set the engine to idle state.
iState = EEngineIdle;
}
 
/*
-------------------------------------------------------------------------------
Symbian Onboard Camera API observer. Gets called after
CCamera::StartViewFinderBitmapsL() is called.
-------------------------------------------------------------------------------
*/

void CCameraEngine::ViewFinderFrameReady(CFbsBitmap& aFrame)
{
// Not important in this snippet
}
 
/*
-------------------------------------------------------------------------------
Symbian Onboard Camera API observer. Gets called after CCamera::CaptureImage()
is called.
-------------------------------------------------------------------------------
*/

void CCameraEngine::ImageReady(CFbsBitmap* aBitmap, HBufC8* aData, TInt aError)
{
// TODO: Error handling
 
// Image saving is not demonstrated in this snippet
// ...
 
// The engine is ready for another go
iState = EEngineIdle;
}
 
/*
-------------------------------------------------------------------------------
Symbian Onboard Camera API observer. Gets called once
CCamera::StartVideoCapture() is called.
-------------------------------------------------------------------------------
*/

void CCameraEngine::FrameBufferReady(MFrameBuffer* aFrameBuffer, TInt aError)
{
// TODO: Error handling
 
// Capturing video is not demonstrated in this snippet
}
 
/*
-------------------------------------------------------------------------------
Takes a picture
-------------------------------------------------------------------------------
*/

void CCameraEngine::SnapL()
{
// Snapping a picture is only possible if the engine is in idle state
if (iState == EEngineIdle)
{
iState = ESnappingPicture;
iCamera->CaptureImage();
 
// On completion, MCameraObserver::ImageReady() will be called
}
else
{
User::Leave(KErrNotReady);
}
}源文件:CAppUi.cpp
 
Code:
#include "CCameraController.h"
This page was last modified on 6 March 2012, at 00:53.
28 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×