欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

cameraview.cpp

《UIQ 3 The Complete Guide》书的源代码
CPP
第 1 页 / 共 2 页
字号:
					// typically used to generate some kind of text display to user...

					TSize size;
					for (TInt j=0;j<info.iNumImageSizesSupported;i++)
						{
						iCamera->EnumerateCaptureSizes(size,j,format);
						if (size.iWidth>0 && size.iHeight>0)
							{ // this format can generate this size image...
							}
						}
					}
				}
*/			


			TRAP(err,

				// start the view finder - displaying the image within our window. We dont have to 
				// do the display, its done by the camera s/w directly.
				TRect rect(Rect());
				rect.Move(PositionRelativeToScreen());
				iCamera->StartViewFinderDirectL(iEikonEnv->WsSession(),*iEikonEnv->ScreenDevice(),Window(),rect);

				// to reduce any latency between when user chooses to take a picture and it being taken
				// we should prepare for the image capture. 
				iCamera->PrepareImageCaptureL(CCamera::EFormatJpeg,info.iNumImageSizesSupported-1);
				);
			}
	
		if (err!=KErrNone)
			{ // display of info.iImageFormatsSupported is as much an internal debug aid as anything else !
			iEikonEnv->Format128(bb,R_STR_CAMERA_POWER_ERROR,err,info.iImageFormatsSupported);
			iEikonEnv->InfoMsg(bb);

			CloseCamera();
			}
		}
	else if (aEvent.iEventType==KUidECamEventCameraNoLongerReserved)
		{ // the camera has been stolen, eg. via higher priority entry. We should shut down
		CloseCamera();
		}
	else
		{
		_LIT(KUnknownCameraEvent,"Unknown camera event");
		iEikonEnv->InfoMsg(KUnknownCameraEvent);
	    }
	}

void CCameraDisplayControl::ViewFinderReady(MCameraBuffer& aCameraBuffer,TInt aError)
	{
	}

void CCameraDisplayControl::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
//
// Called back due to earlier call to CaptureImage()
//
	{
	if (aError==KErrNone)
		{
		// derive the drive and path for this applications private folder - which is 
		// where we will create the image. e.g. "c:\private\20000462\"
		TFileName installedDrive(static_cast<CEikAppUi*>(iEikonEnv->AppUi())->Application()->AppFullName());
		TFileName path;
		iEikonEnv->FsSession().PrivatePath(path); // does not supply a drive letter
		TParse parse;
		parse.Set(path,&installedDrive,NULL);	// add drive here
#ifdef __WINS__
		path=parse.FullName();
		path[0]='C';	// else emul points it at Z: 
		parse.Set(path,NULL,NULL);
#endif

		// create "c:\private\20000462\Photo.jpg" as the file to store our photo in

		path=parse.DriveAndPath();
		_LIT(KPhotoJpg2,"Photo.jpg");
		parse.Set(KPhotoJpg2,&path,NULL);

		RFile file;
		aError=file.Replace(iEikonEnv->FsSession(),parse.FullName(),EFileShareExclusive|EFileWrite);
		if (aError==KErrNone)
			{
			aError=file.Write(*aCameraBuffer.DataL(aCameraBuffer.iIndexOfFirstFrameInBuffer));
			file.Close();
			if (aError==KErrNone)
				{
				// tell the engine about a new entry
				TRAP(aError,
					iEngine->AddEntryL(parse.FullName(),EAppCategoryImage);
					);

				// only now is it fully saved + added to internal data structures..
				iEikonEnv->InfoMsg(R_STR_PHOTO_SAVED);
				}
			}

		// failed to write all the file, or update the engine, roll back to the file not existing
		if (aError!=KErrNone)
			iEikonEnv->FsSession().Delete(parse.FullName());
		}

	if (aError!=KErrNone)
		{
		TBuf<128>bb;
		iEikonEnv->Format128(bb,R_STR_CAMERA_IMAGE_ERROR,aError);
		iEikonEnv->InfoMsg(bb);
		}

    aCameraBuffer.Release();
    CloseCamera();

	// return to list view. If we have managed to successfully save the photo the list view
	// will be updated to contain the entry AND the highlight will be on the photo.jpg entry iff
	// were viewing a category that contains the image
	static_cast<CQikAppUi*>(iEikonEnv->AppUi())->ActivateViewL(KViewIdListView);
	}

void CCameraDisplayControl::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
	{
	}

#endif // USE_CAMERA_OBSERVER_INTERFACE


void CCameraDisplayControl::TakePictureL()
//
// Take a picture. Validate were powered up and have prepared the image for capture.
//
	{
	if (iState==ECameraStateTakingPicture)
		User::Leave(KErrInUse);

	if (iState!=ECameraStatePoweredOn)
		User::Leave(KErrNotSupported);

    iCamera->CaptureImage(); // calls back ImageReady() or ImageBufferReady() depending on build !
	iState=ECameraStateTakingPicture;
	}

void CCameraDisplayControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
//
// Tapping anywhere on screen will cause us to take a picture. 
//
	{
	if (aPointerEvent.iType==TPointerEvent::EButton1Down)
		{
		// for pointer events we de-bounce pointer downs if we happen to get a second one
		// whilst in middle of taking a picture. Reporting InUse is not required for such a condition..
		if (iState!=ECameraStateTakingPicture)
			TakePictureL();
		}
	}

void CCameraDisplayControl::StartViewFinderL()
	{
	// extra paranoia
	CloseCamera();

	// check to see if we have a camera on the current device
	TInt count=CCamera::CamerasAvailable();
	if (count<1)
		User::Leave(KErrNotSupported);


#ifdef USE_CAMERA_OBSERVER_INTERFACE
	iCamera=CCamera::NewL(*this,0);
#else
	iCamera=CCamera::NewL(*this,0,EPriorityNormal);
#endif // USE_CAMERA_OBSERVER_INTERFACE


	iCamera->Reserve(); // calls back HandleEvent() with KUidECamEventReserveComplete
	}

//////////////////////////////////////////////////////////////////////////////////
CCameraView::~CCameraView()
	{
	}

CCameraView::CCameraView(CQikAppUi& aAppUi,CAppEngine* aEngine) :
	CQikViewBase(aAppUi,KViewIdListView),iEngine(aEngine)
	{}

TVwsViewId CCameraView::ViewId() const
//
// All views are uniquely identified within the entire system. A TVwsViewId consists of 
// the application uid (uid3) and app specific view uid
//
	{
	return(KViewIdCameraView);
	}

void CCameraView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
	{
	switch (aCommand.Id())
		{

	default: // e.g. the back button...
		CQikViewBase::HandleCommandL(aCommand);
		break;
		}
	}

TKeyResponse CCameraView::OfferKeyEventL(const TKeyEvent &aKeyEvent,TEventCode aType)
//
// Key press been delivered...  
//
	{
	TKeyResponse ret=EKeyWasNotConsumed;
	if (aType==EEventKey)
		{
		if (aKeyEvent.iCode==EDeviceKeyAction || aKeyEvent.iCode=='5' || aKeyEvent.iCode==EKeyEnter)
			{ // centre of jog, keyb-5 often used for 'fire', enter=do action etc...
			static_cast<CCameraDisplayControl*>(iContainer->Controls().At(0).iControl)->TakePictureL();
			}
		}
	return(ret);
	}

void CCameraView::ViewConstructL()
	{
	// Loads information about the UI configurations this view supports
	// together with definition of each view.	
	ViewConstructFromResourceL(R_CAMERA_VIEW_CONFIGURATIONS);

	// A container type object is expected to exist. The layout manager - as defined in the
	// resource will drive the container, e.g. will call its SetRect() method. 
	CQikContainer* container = new(ELeave)CQikContainer();
	Controls().AppendLC(container);
	container->ConstructL(ETrue);
	container->SetRect(Rect());
	CleanupStack::Pop(container);
	iContainer=container;

	// we have an video display control - is is responsible for displaying any image that
	// has been loaded, handling commands etc.
	CCameraDisplayControl *q=new(ELeave)CCameraDisplayControl(iEngine);
	iContainer->AddControlLC(q);
	q->ConstructL();
	CleanupStack::Pop(q);

	// set the line below app name to be "Take photo"
	TBuf<64> bb;
	iEikonEnv->ReadResourceL(bb,R_STR_TAKE_PHOTO_TITLE);
	ViewContext()->AddTextL(1,bb); 
	}

void CCameraView::ViewDeactivated()
//
// The view is being de-activated.
//
	{
	// ensure we release the camera resource - other apps may want to use it. Symbian Signed requirement
	CCameraDisplayControl *q=static_cast<CCameraDisplayControl *>(iContainer->Controls().At(0).iControl);
	q->CloseCamera();
	}

void CCameraView::ViewActivatedL(
//
// The view is being activated.
//
	const TVwsViewId& aPrevViewId,
	const TUid aCustomMessageId,
	const TDesC8& aCustomMessage)
	{
	// we only have a single control added to the container - so we can get at it like this
	CCameraDisplayControl *q=static_cast<CCameraDisplayControl *>(iContainer->Controls().At(0).iControl);
	q->SetRect(iContainer->Rect());
	q->StartViewFinderL();
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -