×
Namespaces

Variants
Actions

如何处理摄像头资源

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台: S60 3rd Edition, S60 3rd Edition FP1
S60 3rd Edition FP1
S60 3rd Edition (initial release)

文章
翻译:
最后由 hamishwillee 在 30 May 2013 编辑
  • 详细描述

本文章描述了如何保留并释放摄像头资源,当程序激活后(即被带到前台或启动时)或非激活状态(即处于后台或退出)。


为了在获得或失去焦点时正确的处理摄像头资源,程序必须要能响应前台事件。下列代码片段使用MCoeForegroundObserver完成此功能。


该代码可以通过自签名执行。

Contents

前提

要执行该代码,程序需要完成对摄像头的使用(如S60 Platform: Camera Example with Autofocus

MMP文件

需要下列能力和链接库

CAPABILITY UserEnvironment 
 
LIBRARY ecam.lib

头文件

Inherit your class from MCoeForegroundObserver and override the HandleGainingForeground() and

HandleLosingForeground()functions to be able to react to foreground events and handle the camera resource.

#include <ECam.h>           // link against ecam.lib
#include <ccamautofocus.h> // only needed if autofocus extension is meant to be
// used; link against CamAutoFocus.lib
 
...
 
/**
* From MCoeForegroundObserver
*/

virtual void HandleGainingForeground();
virtual void HandleLosingForeground();
 
...
 
CCamera* iCamera;
CCamAutoFocus* iAutoFocus; // optional


源文件

要监听前台时间,需要将监控类设置如下:

iEikonEnv->AddForegroundObserverL( *this );


保留摄像头资源

// Gets called when the application is brought to the foreground
void CYourClass::HandleGainingForeground()
{
iCamera->Reserve(); // Asynchronous. Calls MCameraObserver::ReserveComplete
// when the request completes.
}


释放摄像头资源

// Gets called when the application is sent to the background
void CYourClass::HandleLosingForeground()
{
// Bring the AF subsystem to idle state, in case it is used
TRAPD( err, iAutoFocus->ResetToIdleL() );
if ( !err )
{
iAutoFocus->Close();
}
 
// Release the camera
iCamera->Release();
}
This page was last modified on 30 May 2013, at 04:03.
179 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.

×