📄 cameraappcontroller.cpp
字号:
/*
* Copyright ?2008 Nokia Corporation.
*/
#include <AknViewAppUi.h>
#include <CamTest.rsg>
#include <bautils.h>
#include <PathInfo.h>
#include <sysutil.h> // SysUtil
#include "CameraAppController.h"
#include "CameraAppBaseContainer.h"
#include "CamTestappview.h"
#include "CamTestappui.h"
#include "CameraCaptureEngine.h"
// Constants
const TInt KFileNameIndexMaxLength = 5;
_LIT(KSnapSoundFile, "Camera1a_2_8kHz.wav");
_LIT(KFocusedSoundFile, "focused.wav");
// For 2nd Edition emulator only
#ifdef __WINS__
_LIT(KEmulatorPath, "\\system\\Apps\\cameraapp\\");
#endif
/*
-------------------------------------------------------------------------------
C++ default constructor
-------------------------------------------------------------------------------
*/
CCameraAppController::CCameraAppController(CAknViewAppUi& aAppUi)
:iAppUi( aAppUi ),
iContainer( 0 )
{
}
/*
-------------------------------------------------------------------------------
Destructor. Frees allocated resources.
-------------------------------------------------------------------------------
*/
CCameraAppController::~CCameraAppController()
{
// Power off the camera
PowerOff();
delete iCameraCaptureEngine;
delete iBitmapSnap;
delete iImagePath;
delete iPath;
if (iSoundPlayer)
{
iSoundPlayer->Close();
delete iSoundPlayer;
}
}
/*
-------------------------------------------------------------------------------
Symbian OS 2nd phase constructor
-------------------------------------------------------------------------------
*/
void CCameraAppController::ConstructL()
{
iEikEnv = CEikonEnv::Static(); // CSI: 27 # (Store a pointer to CEikonEnv)
iPath = new(ELeave) TFileName;
// Create the sound player here
CreateSoundPlayerL();
TFileName path = PathInfo::PhoneMemoryRootPath(); //Default
path.Append( PathInfo::ImagesPath() );
iImagePath = HBufC::NewL( path.Length() );
iImagePath->Des().Copy( path );
}
/*
-------------------------------------------------------------------------------
Powers off the camera
-------------------------------------------------------------------------------
*/
void CCameraAppController::PowerOff()
{
iCameraCaptureEngine->PowerOff();
}
/*
-------------------------------------------------------------------------------
Gets the camera orientation
-------------------------------------------------------------------------------
*/
TCameraOrientation CCameraAppController::CameraOrientation() const
{
return iCameraOrientation;
}
/*
-------------------------------------------------------------------------------
Sets the camera orientation
-------------------------------------------------------------------------------
*/
void CCameraAppController::SetCameraOrientation(
TCameraOrientation aCameraOrientation)
{
iCameraOrientation = aCameraOrientation;
}
/*
-------------------------------------------------------------------------------
Sets the capture mode, used for displaying information about image size/format
-------------------------------------------------------------------------------
*/
void CCameraAppController::SetCaptureModeL(const TSize& aSize,
TInt aFormat,
TBool aAFSupported)
{
iCaptureFormat = aFormat;
const TInt KBufferSize = 32;
TBuf<KBufferSize> text;
_LIT(KFormatText, "[%1.1fM]");
const TInt KMega = 1000000;
text.Format(KFormatText, TReal(aSize.iWidth * aSize.iHeight) / KMega );
if( iCaptureFormat == CCamera::EFormatExif )
{
_LIT(KExifText, "EXIF");
text.Append(KExifText);
}
if( aAFSupported )
{
_LIT(KAfText, "/AF");
text.Append(KAfText);
CCamAutoFocus::TAutoFocusRange range;
iCameraCaptureEngine->FocusRange(range);
switch( range )
{
case CCamAutoFocus::ERangeMacro:
{
_LIT(KMacroText, "(m)");
text.Append(KMacroText);
break;
}
case CCamAutoFocus::ERangePortrait:
{
_LIT(KPortraitText, "(p)");
text.Append(KPortraitText);
break;
}
case CCamAutoFocus::ERangeNormal:
{
_LIT(KNormalText, "(n)");
text.Append(KNormalText);
break;
}
case CCamAutoFocus::ERangeInfinite:
{
_LIT(KInfiniteText, "(i)");
text.Append(KInfiniteText);
break;
}
default:
break;
}
}
}
/*
-------------------------------------------------------------------------------
Checks if AF is supported
-------------------------------------------------------------------------------
*/
TBool CCameraAppController::IsAutoFocusSupported()
{
return iCameraCaptureEngine->IsAutoFocusSupported();
}
/*
-------------------------------------------------------------------------------
Sets the autofocus range //设置自动对焦 范围
-------------------------------------------------------------------------------
*/
void CCameraAppController::SetFocusRangeL(
CCamAutoFocus::TAutoFocusRange aRange)
{
iCameraCaptureEngine->SetFocusRangeL(aRange);
}
/*
-------------------------------------------------------------------------------
Returns the default display mode
-------------------------------------------------------------------------------
*/
TDisplayMode CCameraAppController::DisplayMode() const
{
return iCameraCaptureEngine->DisplayMode();
}
/*
-------------------------------------------------------------------------------
Initializes still image capture engine
-------------------------------------------------------------------------------
*/
void CCameraAppController::InitializeCameraL(const TRect& aRect)
{
if (!iCameraCaptureEngine)
{
iCameraCaptureEngine = CCameraCaptureEngine::NewL( this, aRect );
//Create snap image
iBitmapSnap = new (ELeave) CWsBitmap(iEikEnv->WsSession());
User::LeaveIfError( iBitmapSnap->Create(aRect.Size(), DisplayMode()));
}
}
/*
-------------------------------------------------------------------------------
Starts the view finding operation
-------------------------------------------------------------------------------
*/
void CCameraAppController::StartViewFinderL()
{
if (iCameraCaptureEngine)
{
if(iCameraCaptureEngine->GetEngineState() == EEngineNoHardware)
{
HandleError( KErrHardwareNotAvailable );
return;
}
if(iCameraCaptureEngine->IsViewFinderActive())
return;
iCameraCaptureEngine->SetOrientation(iCameraOrientation);
iCameraCaptureEngine->StartViewFinderL();
}
}
/*
-------------------------------------------------------------------------------
Gives to Controller the reference to Active view container
-------------------------------------------------------------------------------
*/
void CCameraAppController::SetAppContainer( CCameraAppBaseContainer* aAppContainer)
{
iContainer = aAppContainer;
}
/*
-------------------------------------------------------------------------------
Returns the complete path of the saved image
-------------------------------------------------------------------------------
*/
const TDesC& CCameraAppController::ImagePath() const
{
return *iImagePath;
}
/*
-------------------------------------------------------------------------------
Set the actual bitmap size
-------------------------------------------------------------------------------
*/
void CCameraAppController::SetActualVFSize( const TSize& /*aSize*/ )
{
if ( iContainer )
{
iContainer->ReDrawOffScreenBitmap( );
}
}
/*
-------------------------------------------------------------------------------
Gets the image from image capture engine and displays it on the screen.
Called by the capture engine to display the bitmap.
-------------------------------------------------------------------------------
*/
void CCameraAppController::ViewFinding( CFbsBitmap& aFrame )
{
// skip frames if it was requested
if ( iSkipFrames )
{
--iSkipFrames;
return;
}
if ( !iContainer )
{
return;
}
if (iContainer)
{
iContainer->DrawImageNow( aFrame );
}
}
/*
-------------------------------------------------------------------------------
Stops view finding
-------------------------------------------------------------------------------
*/
void CCameraAppController::StopViewFinder()
{
if (iCameraCaptureEngine)
iCameraCaptureEngine->StopViewFinder();
}
/*
-------------------------------------------------------------------------------
Takes an image
-------------------------------------------------------------------------------
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -