×
Namespaces

Variants
Actions

如何处理摄像头资源问题

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

平台安全性
需要的签名: Self-Signed
能力: UserEnvironment

文章
关键词: ECam, MCoeForegroundObserver
User:Jiangbaolan 在 02 Apr 2009 创建
最后由 hamishwillee 在 14 Jun 2013 编辑

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

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

前提 要执行该代码,程序需要完成对摄像头的使用(如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.
}

释放摄像头资源

This page was last modified on 14 June 2013, at 08:00.
63 page views in the last 30 days.
×