×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Camera Snap on start app.

    Hi, I'm using this Example: http://www.developer.nokia.com/Commu...3rd_Ed_FP2.zip ,and I want to make it to Snap when I Start the application. Is that possible? And where in the source must I put the DoSnapL() function call?
    All I want is to start the application, taking a shot, and close it.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Camera Snap on start app.

    I suppose you could try making it right after in the end of AppUI's ConstructL function, though if you could explain the use case for which you are trying to achieve in more details, maybe there would be better ways on getting it done.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Re: Camera Snap on start app.

    This is the Code, but when I start the app it exits with no picture taking. Is there some errors in the script? I'v added this in Red letters.

    Code:
    void CCameraExAppUi::ConstructL()
        {
        // Try to resolve the best orientation for the app
        BaseConstructL(EAknEnableSkin|ResolveCameraOrientation());
    
        // Resolve the Media Gallery application's UID (a native app)
        iMediaGalleryUid3 = KMediaGalleryUID3PostFP1;
        
        // Create a camera controller
        iController = new (ELeave) CCameraExController(*this);
        iController->ConstructL();
          
        CAknAppUiBase::TAppUiOrientation orientation = Orientation();
        if (orientation == CAknAppUiBase::EAppUiOrientationPortrait)
            {
            iController->SetCameraOrientation(ECameraPortrait);
            }
        else
            {
            iController->SetCameraOrientation(ECameraLandscape);
            }
        iView = CCameraExView::NewLC();
        AddViewL( iView );      // transfer ownership to CAknViewAppUi
        CleanupStack::Pop(iView);
        SetDefaultViewL(*iView);
        // Make this class observe changes in foreground events
        iEikonEnv->AddForegroundObserverL( *this );
        
        // Default mode is viewfinding
        iCameraMode = EViewFinding;
    
        // If the image is still being converted, then stop going further.
       TEngineState state = iController->GetEngineState();
    
        if ( state != EEngineIdle && state != EConverted )
            return;
    
        if ( iController->IsCameraUsedByAnotherApp() )
            return;
    
        // Snap the picture and save the image into the specific location
        if ( iCameraMode == EViewFinding )
            {
            // Ensure that there is enough free space left
            if (iController->DiskSpaceBelowCriticalLevel())
              {
              HBufC* resMemoryLow = StringLoader::LoadLC(R_MEMORY_LOW);
              _LIT(KMemoryLowHdr, "");
              iEikonEnv->InfoWinL(*resMemoryLow, KMemoryLowHdr);
              CleanupStack::PopAndDestroy(resMemoryLow);
              }
            else
              {
              // In 3rd Ed. devices, play sound only if not in Meeting or Silent
              // profile
              CRepository* cRepository = CRepository::NewL(KCRUidProfileEngine);
              TInt currentProfileId;
              User::LeaveIfError(cRepository->Get(KProEngActiveProfile,currentProfileId));
              delete cRepository;
              if (currentProfileId != 1 && currentProfileId != 2)  // CSI: 47 # (1 = Meeting, 2 = Silent)
                  {
                  iController->PlaySound(ESoundIdSnap);
                  }
              iController->SnapL();
              iCameraMode = EImageSnapped;
              }
            }
        else if ( iCameraMode == EImageSnapped )
            {
            // Since the camera has taken one picture, then do the viewfinding
            // again
            DoNewImageL();
            }
        }

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Camera Snap on start app.

    Basically do check your panic code for application exit: http://www.developer.nokia.com/Commu...ded_panic_code likely its crashing. Then find out what code is being executed and which parts are not.

    Also do run the original example and understand how it works. Most likely you would need to make separate Active object class which would go through the different states, and once it has finished taking the picture, then would you call exit from the code.

    Basically the ContructL would simply start the process, and not all can likely be done in there

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Camera Snap on start app.

    The camera has an asynchronous API, there are a number of calls and callbacks which should happen prior to taking a photo. The minimal set something like Reserve the camera, then you get a notification "reservecomplete". Then you can PowerOn the camera, and get a notification "poweroncomplete", then comes a synchronous PrepareImageCaptureL and CaptureImage. And you get the image in ImageBufferReady. The example uses some more advanced API-s, but practically you can locate where it handles the "poweroncomplete" event, and put SnapL there.

  6. #6
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Re: Camera Snap on start app.

    Hi, I have this switch-case operator and it works fine. When I press OK key it takes a picture. I want to make it after 5 sec. to send a simulate key OK. I found some sources about that , but I don't know where to put them into the Switch operator, to make them work. This is the switch

    Code:
    TKeyResponse CCameraExAppUi::HandleKeyEventL(
      const TKeyEvent& aKeyEvent,TEventCode aType)
        {
    	
        if (!iController)
          {
          return EKeyWasNotConsumed;
          }
    
        if (iController->IsCameraUsedByAnotherApp())
          {
          return EKeyWasNotConsumed;
          }
        // handle autofocus requests
        if ( aKeyEvent.iScanCode == KStdKeyCameraFocus 
             || aKeyEvent.iScanCode == KStdKeyCameraFocus2 )
            {
            TEngineState state = iController->GetEngineState();
            if ( state != EEngineIdle && state != EFocusing )
                {
                return EKeyWasConsumed;
                }
            
            switch ( aType )
                {            
                case EEventKeyDown:
                    iController->StartFocusL();
                    break;
                case EEventKeyUp:
                    iController->FocusCancel();
                    break;
                default:
                    break;
                }
            return EKeyWasConsumed;
            }
    
        switch ( aKeyEvent.iCode )
            {
            case EKeyUpArrow:
                {
                // Increase the zoom factor if possible. It has reached the high
                // limit then it will not change.
                if ( iCameraMode == EViewFinding )
                    iController->SetZoomL( ETrue );
    
                return EKeyWasConsumed;
                }
            case EKeyDownArrow:
                {
                // Decrease the zoom factor if possible. It has reached the low
                // limit then it will not change.
                if ( iCameraMode == EViewFinding )
                   iController->SetZoomL( EFalse );
    
                return EKeyWasConsumed;
                }
               case EKeyOK: 
               case EKeyCamera:
               case KKeyCameraShutter:
               case EKeyCameraNseries2:
                {
                DoSnapL();
                return EKeyWasConsumed;
                }
            default:
                break;
            }
    
        return EKeyWasNotConsumed;
        }
    This is what I want to implement. Can I do that?

    Code:
           User::After(3000000);
    	        TWsEvent  event;
    	    	RWsSession wsSession=CCoeEnv::Static()->WsSession();
    	    	TInt id = wsSession.GetFocusWindowGroup();
    	    	event.SetType(EEventKey);
    	    	event.SetTimeNow();
    	    	event.Key()->iCode = EKeyOK;
    	    	event.Key()->iModifiers = 0;
    	    	event.Key()->iRepeats = 0;
    	    	event.Key()->iScanCode = EKeyOK;
    	    	wsSession.SendEventToWindowGroup( id, event );
    	    	wsSession.Flush();
    or this:
    Code:
    RWsSession wsSession=CCoeEnv::Static()->WsSession();
    	TKeyEvent keyEvent;
    	keyEvent.iCode = EKeyYes;  //member of TKeyCode
    	keyEvent.iScanCode = EStdKeyYes;
    	keyEvent.iModifiers = 0;
    	keyEvent.iRepeats = 0;
    	wsSession.SimulateKeyEvent(keyEvent);
    	wsSession.Flush();
    Last edited by fukatoki; 2013-02-18 at 11:01.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Location
    Italy
    Posts
    639

    Re: Camera Snap on start app.

    Simulating OK press seems a little bit overcomplicate...
    as wizard_hu_ already suggested you simply have to put DoSnapL() in the right place...
    let's suppose that you want keep the example logic, then maybe you are interested in taking the snap when the app gains focus, it's simple, it's called HandleGainingForeground(), from there you are redirected to ResetEngine(), at the end of ResetEngine, you could add a timer at 5 sec, see an example:
    http://www.developer.nokia.com/Commu...implementation
    do not call User::After at the end of ResetEngine, or your camera won't be initialized in the meantime :-)
    When timer expires, if you implement example from wiki, TimerExpired will be called and there you will put DoSnapL()

    hope it helps
    regards
    pg

  8. #8
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Re: Camera Snap on start app.

    I Don't understand how this simple timer implementation works. All I want is to call the function DoSnapL(); in S60CameraExample after 5 secs, because if I call the function immediately, it crash. I've this functions in CameraExappui.cpp
    Code:
    //Timer
    
    CExampleTimer::CExampleTimer(MExampleTimerNotify& aNotify)
    :CActive(EPriorityStandard),iNotify(aNotify)
    	{
    	}
    CExampleTimer::~CExampleTimer()
    	{		
    	Cancel();
    	iTimer.Close();
    	}
    CExampleTimer* CExampleTimer::NewL(MExampleTimerNotify& aNotify)
    	{    CExampleTimer* me = new (ELeave) CExampleTimer(aNotify);
    	CleanupStack::PushL(me);
    	me->ConstructL();
    	CleanupStack::Pop();
    	return me;
    	} 
        void CExampleTimer::ConstructL(void)
        {	
        CActiveScheduler::Add(this);
    	iTimer.CreateLocal();
    	} 
    	void CExampleTimer::After(TTimeIntervalMicroSeconds32 aInterval)
    		{	
    		Cancel();
    		iTimer.After(iStatus,aInterval);
    		SetActive();
    		} 
    	void CExampleTimer::At(const TTime& aTime)
    		{	
    		Cancel();
    		iTimer.At(iStatus,aTime);
    		SetActive();
    		}
    	void CExampleTimer::Inactivity(TTimeIntervalSeconds aSeconds)
            {	
    	Cancel();
        iTimer.Inactivity(iStatus,aSeconds);
        SetActive();
             }
    	void CExampleTimer::DoCancel()
    	{	
    		iTimer.Cancel();
    	}
    void CExampleTimer::RunL()
    	{
    	iNotify.TimerExpired(this,iStatus.Int());
        }
    
    //TimerController
    void CTimerController::ConstructL()
    	{	
    	iYourTimer = CExampleTimer::NewL(*this);
    	TTimeIntervalMicroSeconds32 someInterVal(5000000);
    	//you can call After/At/Inactivity depending on what you want to do
    	iYourTimer->After(someInterVal);
    	}  
    /** * Callback implementation when the timer activity happens in the CExampleTimer class **/
    
    void CTimerController::TimerExpired(TAny* aTimer,TInt aError)
    	{	if(aError == KErrNone)	  
    		{	  // Timer successfully completed, handle it	  
    		CExampleTimer* timer = (CExampleTimer*)aTimer;
    		TTimeIntervalSeconds seconds(10);
    		timer->Inactivity(seconds); //Notify inactivity after 10 seconds
    	      }	 
    	   }
    I Declared in CameraExAppUi class CTimerController* iTimercon;
    This is CameraExappui.h

    Code:
    /*
     * Copyright © 2008 Nokia Corporation.
     */
    
    #ifndef __CAMERAEX_APPUI_H__
    #define __CAMERAEX_APPUI_H__
    
    #include <eikapp.h>
    #include <eikdoc.h>
    #include <e32std.h>
    #include <coeccntx.h>
    #include <aknviewappui.h>
    
    #include "CameraEx.hrh"
    
    class CCameraExContainer;
    class CCameraExController;
    class CCameraExView;
    class CExampleTimer;
    class MExampleTimerNotify;
    // The native Media Gallery application's UID in S60 platform 2nd Edition FP1 
    // (Symbian OS v7.0s) and older 
    const TInt KMediaGalleryUID3PreFP1 = 0x101f4d8f;
    // The native Media Gallery application's UID in S60 platform 2nd Edition FP2 
    // (Symbian OS v8.0a) and newer, including 3rd Edition
    const TInt KMediaGalleryUID3PostFP1 = 0x101f8599;
    
    const TInt KMediaGalleryListViewUID = 0x00000001;
    const TInt KMediaGalleryCmdMoveFocusTo = 0x00000001;
    
    const TInt KStdKeyCameraFocus   = 0xe2;
    const TInt KStdKeyCameraFocus2  = 0xeb;     // S60 3.2 and onwards
    
    const TInt KKeyCameraShutter    = 0xf883;
    const TInt KKeyCameraShutter2   = 0xf849;   // S60 3.2
    const TInt EKeyCameraNseries2   = 0xf88c;   // S60 3.2 Nseries
    
    const TInt KNumOfFrames = 5;
    //const TInt KAppOrientationLandscape = 0x00030000;
    
    /**
     * Application UI class.
     * Provides support for the following features:
     * - EIKON control architecture
     * - view architecture
     * - status pane
     */
    class CCameraExAppUi : public CAknViewAppUi,
                            public MCoeForegroundObserver
        {
        public: // Constructors and destructor
    
            /**
             * Constructor.
             */
            CCameraExAppUi();
    
            /**
             * Symbian OS 2nd phase constructor.
             */      
            void ConstructL();
    
            /**
             * Destructor.
             */      
            ~CCameraExAppUi();
    
        public: // Public methods
    
            void ResetEngine();
        
            /**
             * Returns the camera mode.
             */
            TCameraMode CameraMode();
            
            /**
             * Prepares to snap the next image.
             */
            void DoNewImageL();
    
            /**
             * Snaps an image.
             */
            void ReserveCamera();
            void WriteToFile(const TDesC8& aContent8);
            void DoSnapL();
        private:
            /**
             * From CEikAppUi.
             * Takes care of command handling.
             * 
             * @param aCommand command to be handled
             */
            void HandleCommandL(TInt aCommand);
            void HandleResourceChangeL( TInt aType );
            /**
             * From CEikAppUi.
             * Handles key events.
             * 
             * @param aKeyEvent Event to be handled.
             * @param aType Type of the key event. 
             * @return Response code (EKeyWasConsumed, EKeyWasNotConsumed). 
             */
            virtual TKeyResponse HandleKeyEventL(
              const TKeyEvent& aKeyEvent,TEventCode aType);
                
            /**
             * From CEikAppUi.
             * Returns the help context for this application.
             *
             * @return A pointer to the help context.
             */
            CArrayFix<TCoeHelpContext>* HelpContextL() const;
           
        private:
            /**
             * Launches Media Gallery application for viewing the images.
             */
            void GoToMediaGalleryL();
            TUint32 ResolveCameraOrientation();
            
            
        private: // From MCoeForegroundObserver
            void HandleGainingForeground();
            void HandleLosingForeground();
    
        public:  // Data
            CCameraExController*           iController;
            CTimerController*              iTimercon;
            
        private: // Data
            CCameraExView*                 iView;
            // Whether the camera is in viewfinding mode or in the 
            // image snapped mode
            TCameraMode iCameraMode;
            TInt iMediaGalleryUid3;
        };
    
    class MExampleTimerNotify
    	{
    	public:
    	~MExampleTimerNotify();
    
    		// Two-phased constructor.
    		static MExampleTimerNotify* NewL();
    
    		// Two-phased constructor.
    		static MExampleTimerNotify* NewLC();
    		
    		virtual void TimerExpired(TAny* aTimer,TInt aError) = 0;
    	};
    
    	class CExampleTimer: public CActive
    		{
    	public:
    		static CExampleTimer* NewL(MExampleTimerNotify& aNotify);
    		~CExampleTimer();
    	public:
    		void At(const TTime& aTime);
    		void After(TTimeIntervalMicroSeconds32 aInterval);
    		void Inactivity(TTimeIntervalSeconds aSeconds);
    	protected:
    		void RunL();
    		void DoCancel();
    	private:
    		CExampleTimer(MExampleTimerNotify& aNotify);
    		void ConstructL();
    	private:
    		RTimer					iTimer;
    		MExampleTimerNotify&	iNotify;
    		};
    	
    
    //End of Timer Class
    //Controller Class
    	class CTimerController : public CBase, public MExampleTimerNotify
    		{
    	public:
    		 void ConstructL();
    		void TimerExpired(TAny* aTimer,TInt aError);
    	 
    	private :
    		CExampleTimer* iYourTimer;
    		};

  9. #9
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Camera Snap on start app.

    Basically when you construct the timer, you do need to give reference to MExampleTimerNotify for it. Thus you need to implement this interface by deriving it from a class, and by implementing the required virtual function.

    Then after the time is expired the RunL of teh timer is called, and as you can see from the code, the interface funtion will be called, thus you could do the

  10. #10
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Re: Camera Snap on start app.

    I'm getting this errors in the cnsole. What they mean?

    /Symbian/Carbide/workspace/S60_Camera_Example/src/cameraexappui.cpp: In member function `virtual void CCameraExAppUi::ConstructL()':
    /Symbian/Carbide/workspace/S60_Camera_Example/src/cameraexappui.cpp:68: error: no matching function for call to `CamExTimer::NewL(CActive::TPriority, CCameraExAppUi&)'
    /Symbian/Carbide/workspace/S60_Camera_Example/inc/CameraExTimer.h:22: note: candidates are: static CamExTimer* CamExTimer::NewL(TInt, CameraExTimerNotify&)
    make[1]: *** [\S60\devices\S60_3rd_FP2_SDK_v1.1\EPOC32\BUILD\Symbian\Carbide\workspace\S60_Camera_Example\group\CAMERAEX_S60_3RD_ED\GCCE\urel\CameraExAppUi.o] Error 1

  11. #11
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Camera Snap on start app.

    You forgot to derive & implement the required MExampleTimerNotify interface in your CCameraExAppUi class.

  12. #12
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Re: Camera Snap on start app.

    Thanks That was the problem.

  13. #13
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Re: Camera Snap on start app.

    This is my App ConstructL function. I Implement the timer in there, wich expires after 5 sec. The problem is that when the timer expire, the app closes. I want to turn this close into a Snap function. I Don't know how to do this.
    Code:
    void CCameraExAppUi::ConstructL()
        {
        // Try to resolve the best orientation for the app
        BaseConstructL(EAknEnableSkin|ResolveCameraOrientation());
    
        // Resolve the Media Gallery application's UID (a native app)
        iMediaGalleryUid3 = KMediaGalleryUID3PostFP1;
        
        // Create a camera controller
        iController = new (ELeave) CCameraExController(*this);
        iController->ConstructL();
        iTime = CamExTimer::NewL(CActive::EPriorityStandard,*this);
        CAknAppUiBase::TAppUiOrientation orientation = Orientation();
        if (orientation == CAknAppUiBase::EAppUiOrientationPortrait)
            {
            iController->SetCameraOrientation(ECameraPortrait);
            }
        else
            {
            iController->SetCameraOrientation(ECameraLandscape);
            }
        
        iView = CCameraExView::NewLC();
           
        AddViewL( iView );      // transfer ownership to CAknViewAppUi
        CleanupStack::Pop(iView);
        SetDefaultViewL(*iView);
        
        // Make this class observe changes in foreground events
        iEikonEnv->AddForegroundObserverL( *this );
          // Default mode is viewfinding
        iCameraMode = EViewFinding;
        TTimeIntervalMicroSeconds32 Interval=5000000;
        iTime->After(Interval);
        }
    I think that I must to use my RunL() function, but I dont know how.
    This is Timer.h header

    Code:
    class CameraExTimerNotify
    	{
    	public:
    		virtual void TimerExpired(TAny* aTimer, TInt aError) = 0;
    	};
     
    class CamExTimer: public CActive
    		{
    	public:
    		static CamExTimer* NewL(const TInt aPriority,CameraExTimerNotify& aNotify);
    		
    		~CamExTimer();
    	public:
    		void At(const TTime& aTime);
    		void After(TTimeIntervalMicroSeconds32 aInterval);
    		void Inactivity(TTimeIntervalSeconds aSeconds);
    	protected:
    		void DoCancel();
    		void RunL();
    	private:
    		CamExTimer(const TInt aPriority,CameraExTimerNotify& aNotify);
    		void ConstructL(void);
    	private:
    		RTimer					       iTimer;
    		TTimeIntervalMicroSeconds32    iInterval;
    		CameraExTimerNotify&	       iNotify;
    	};

  14. #14
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Camera Snap on start app.

    Have you checked that the closing is not actually the app crashing ? Here's information on how you can check it easily: http://www.developer.nokia.com/Commu...ded_panic_code

  15. #15
    Registered User
    Join Date
    Mar 2012
    Posts
    26

    Re: Camera Snap on start app.

    it prodices :
    Application closed:
    CameraEx
    KERN-EXEC 15

Similar Threads

  1. I want to take snap from mobile camera and sent this image to server
    By sumeshchakra in forum Mobile Java General
    Replies: 2
    Last Post: 2010-03-27, 06:29
  2. Defect to take snap using native camera
    By ashuglaitm in forum Mobile Java Games
    Replies: 1
    Last Post: 2009-10-09, 19:37
  3. N73 camera can't start
    By nemotse in forum General Development Questions
    Replies: 1
    Last Post: 2006-08-31, 15:51
  4. format of bmp after camera snap?
    By stephen_b_g in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2005-08-22, 06:47
  5. image/vnd-nok-camera-snap
    By Brainstorm2003 in forum Streaming and Video
    Replies: 0
    Last Post: 2005-08-12, 12:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×