Mangiare Senza Glutine disponibile su App Store

Per altre informazioni scrivi a fabriziocaldarelli@negusweb.it

Usare la Camera su Symbian Qt 4.6

Da Programmazione Software.

Qt 4.6, in concomitanza con le QtMobility 1.0.2, non dispone di un oggetto per l'utilizzo della fotocamera (per la cattura dei singoli fotogrammi).

A tal proposito è quindi necessario ricorrere al buon vecchio Symbian C++, un pò più a basso livello, attraverso la CCamera Api.

Di seguito il codice sufficiente ad utilizzare la camera (minimale).

Ricordasi di :

Aggiungere la capability UserEnvironment 
Linkare le librerie ecam.lib (per l'uso della camera) e fbscli.lib (per il passaggio delle immagini);

Tutto il codice è scaricabile da: CameraTest Symbian Qt 4.6


CameraTest.pro

  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2010-12-28T15:23:16
  4. #
  5. #-------------------------------------------------
  6.  
  7. QT       += core gui
  8.  
  9. TARGET = cameratest
  10. TEMPLATE = app
  11.  
  12.  
  13. SOURCES += main.cpp\
  14.         mainwindow.cpp
  15.  
  16. HEADERS  += mainwindow.h
  17.  
  18. FORMS    += mainwindow.ui
  19.  
  20. CONFIG += mobility
  21. MOBILITY = 
  22.  
  23. symbian {
  24.     TARGET.UID3 = 0xe54fbdb9
  25.     TARGET.CAPABILITY += UserEnvironment
  26.     TARGET.EPOCSTACKSIZE = 0x14000
  27.     TARGET.EPOCHEAPSIZE = 0x020000 0x800000
  28.  
  29.     LIBS += -lecam -lfbscli
  30. }
  31.  
  32. debug {
  33.     MMP_RULES -= PAGED
  34.     MMP_RULES += UNPAGED
  35. }


MainWindow.h

  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QLabel>
  6.  
  7. #ifdef Q_WS_S60
  8. #include <ecam.h>
  9. #include <fbs.h>
  10. #endif
  11.  
  12. namespace Ui {
  13.     class MainWindow;
  14. }
  15.  
  16. class MainWindow : public QMainWindow, public MCameraObserver2
  17. {
  18.     Q_OBJECT
  19.  
  20. public:
  21.     explicit MainWindow(QWidget *parent = 0);
  22.     ~MainWindow();
  23.  
  24. private:
  25.     void HandleEvent(const TECAMEvent& aEvent);
  26.     void ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError);
  27.     void ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError);
  28.     void VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError);
  29.  
  30.     void UseCamera();
  31.  
  32.  
  33. private:
  34.     Ui::MainWindow *ui;
  35.  
  36.     CCamera         *iCamera;
  37.  
  38. };
  39.  
  40. #endif // MAINWINDOW_H


MainWindow.cpp

  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QDebug>
  4.  
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7.     QMainWindow(parent),
  8.     ui(new Ui::MainWindow)
  9. {
  10.     ui->setupUi(this);
  11.  
  12.     this->UseCamera();
  13. }
  14.  
  15. MainWindow::~MainWindow()
  16. {
  17.     delete ui;
  18. }
  19.  
  20. void MainWindow::HandleEvent(const TECAMEvent& aEvent)
  21. {
  22.     qDebug()<< "HandleEvent";
  23.  
  24.     if (aEvent.iEventType == KUidECamEventReserveComplete)
  25.     {
  26.         //Reserve Complete
  27.         qDebug()<<"Reserve Complete";
  28.         iCamera->PowerOn();
  29.     }
  30.  
  31.     if (aEvent.iEventType == KUidECamEventPowerOnComplete)
  32.     {
  33.         //PowerOn Complete
  34.         qDebug()<<"PowerOn complete";
  35.  
  36.         TSize sz(360,270);
  37.         iCamera->StartViewFinderBitmapsL(sz);
  38.     }
  39. }
  40.  
  41. void MainWindow::ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError)
  42. {
  43.     qDebug() << "ViewFinderReady";
  44.     if (this->isVisible())
  45.     {
  46.         CFbsBitmap bmp;
  47.         bmp.Duplicate(aCameraBuffer.BitmapL(0).Handle());
  48.         QPixmap pxm = QPixmap::fromSymbianCFbsBitmap(&bmp);
  49.         ui->lblPreview->setPixmap(pxm);
  50.     }
  51.  
  52.     aCameraBuffer.Release();
  53. }
  54.  
  55. void MainWindow::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
  56. {
  57.     qDebug() << "ImageBufferReady";
  58. }
  59.  
  60. void MainWindow::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
  61. {
  62.     qDebug() << "VideoBufferReady";
  63.     aCameraBuffer.Release();
  64. }
  65.  
  66. void MainWindow::UseCamera()
  67. {
  68.     this->iCamera = CCamera::New2L(*this, 0, 0);
  69.     this->iCamera->Reserve();
  70. }
Strumenti personali
hobby
approfondimenti