MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Using the device camera

Harmattan devices include two cameras. The primary camera is in the back, and a secondary camera is in front. These cameras are often referred to as rear camera and front camera, respectively. For technical specifications of the cameras, see Nokia N9 device specifications.

The rear camera is intended for high-resolution photos and video capture. The front camera is a lower resolution camera intended for web chat applications and other similar uses. A normal usage for applications using either camera is to create a viewfinder object that shows a live preview signal on the device screen from the selected camera and then capture the still image or start recording the video clip through user interaction. On default settings, the cameras feature a lot of automation, including aperture control and auto-focus.

The cameras are implemented with Qt Mobility Multimedia API, which requires additional security credentials, as described in section Harmattan APIs that require credentials. However, when you use the Qt SDK for development, it handles assigning the credentials automatically.

Using the primary camera

In Harmattan, there are multiple ways to use the primary camera that is located on the device rear side:

  • FCam - Provides mechanisms to control various components of the Nokia N9 camera to facilitate complex photographic applications.
  • Camerabin2 - An open source framework based on GStreamer.
  • QCamera object - The standard Qt object for handling the device camera.
  • QML Camera element - A built-in QML element for the camera viewfinder and related activities. Does not directly support the secondary camera.
  • V4L2 - Allows low-level access to camera resources.

Using the QML camera element to capture images is usually the easiest way to implement camera functionality in your application. If your application in general uses QML, this is the recommended choice. QML camera element is a part of QtMultiMediaKit module in Qt Mobility.

The following example implements a simple camera feature:

import QtQuick 1.1
import 1.0
import QtMultimediaKit 1.1

PageStackWindow {
   id: appWindow

   initialPage: mainPage

   Page {
       id: mainPage

       Camera {
          id: primaryCamera
          focus: visible
          anchors.centerIn:  parent
          captureResolution: "640x360"

The image is captured with the Camera.start method that you can assign, for example, to a Button or a timer.

The QML Camera element requires that you use QGLWidget as its viewport. Using other viewpoints may result in application crash when the application is swiped to background. An example QGLWidget initialization in the application main.cpp file can look like the following:

#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtDeclarative>

int main(int argc, char *argv[])
    QApplication app(argc, argv);
    QDeclarativeView view;
    view.setViewport(new QGLWidget());
    return app.exec();

Using the secondary camera

The front camera is most conveniently implemented as a QCamera object. Its usage is similar to the rear camera QCamera object, but the way the object is initialised changes. To intialise the camera, read it from the availableDevices array where it is the second element QCamera::availableDevices()[1]. Although the primary camera is selected by default, you can also initialise it from the [0] array element if needed.

#include <QGraphicsVideoItem>

FrontCameraApp::FrontCameraApp(QDeclarativeItem *parent) : QDeclarativeItem(parent)
   myViewfinder = new QGraphicsVideoItem(this);
   QByteArray frontCamera = QCamera::availableDevices()[1];
   myCamera = new QCamera(frontCamera);