quick_recipes (779892), страница 46
Текст из файла (страница 46)
Each method has some more variants; we will notdiscuss all of them.CCamera::StartViewFinderDirectL() is used to start the directviewfinder:virtual void StartViewFinderDirectL(RWsSession& aWs,CWsScreenDevice& aScreenDevice, RWindowBase& aWindow,TRect& aScreenRect)=0;258SYMBIAN C++ RECIPESYou would usually use CCoeEnv::WsSession(), CCoeEnv::ScreenDevice() and CCoeControl::DrawableWindow() to assign the first three parameters.The last parameter is the area where the viewfinder will be displayed.The position is relative to the origin of the screen.CCamera::StartViewFinderBitmapsL() is used to start thebitmap viewfinder:virtual void StartViewFinderBitmapsL(TSize& aSize);StartViewFinderBitmapsL() requires one parameter with typeTSize, which is the size of the viewfinder to be used. When callingStartViewFinderBitmapsL(), you have to initialize aSize withthe area where you want to display the viewfinder.
On return, aSize willbe assigned to the actual size of the viewfinder. They may be differentbecause the control size and the viewfinder size may have different aspectratio.You can only display the viewfinder after the camera’s power has beenswitched on. This means you have to do it after MCameraObserver::PowerOnComplete() has been called.In the case of a direct viewfinder, you don’t need to do anything elseafter calling StartViewFinderDirectL(). The viewfinder drawing isdone direct to the screen by the API.When using a bitmap viewfinder, you have to draw the viewfinder manually. MCameraObserver::ViewFinderFrameReady() is calledperiodically when the new viewfinder frame is ready.
This callbackhas one parameter with type CFbsBitmap&, which is the viewfinder tobe displayed.There are applications that may require the viewfinder to process theimage from the camera without actually capturing it. For example, it canbe used in a motion detector application. When the application detectsa moving object, it performs a specific action (this is discussed furtherin the Symbian Press book Games on Symbian OS – see developer.symbian.com/gamesbook for more details). A game may also use aviewfinder as its controller. When the user moves the camera in onedirection, a character in the game also moves in the same direction.4.7.3.4Capture Still Images from a CameraAmount of time required: 20 minutesLocation of example code: \Multimedia\CameraImageRequired libraries: ecam.libRequired header file(s): ecam.hRequired platform security capability(s): UserEnvironmentMULTIMEDIA259Problem: You want to capture still images from the device’s camera.
Theimages are then saved to a file in JPEG format.Solution: In the recipe, the CCameraEngine::CaptureImageL()method is used to capture still images from the camera. This is anasynchronous method. When complete, it calls CCameraEngine::DoSaveImageL() to save the image to a file.Discussion:Preparing image captureCapturing a still image using a camera is done by calling CCamera::CaptureImage(). This is an asynchronous method. When itcompletes, it calls MCameraObserver::ImageReady().Before capturing any image, the CCamera::PrepareImageCaptureL() method has to be called to keep the latency of CaptureImage() to a minimum. It needs to be called only once formultiple CaptureImage() calls.The PrepareImageCaptureL() method requires two parameters.The first parameter is the format of the image.
Here is the list of formatsfor still images:• EFormatMonochrome• EFormat16bitRGB444• EFormat16BitRGB565• EFormat32BitRGB888• EFormatJpeg• EFormatExif• EFormatFbsBitmapColor4K• EFormatFbsBitmapColor64K• EFormatFbsBitmapColor16M• EFormatFbsBitmapColor16MU.One device may not support all the formats above. You can checkwhich formats are supported by a device from TCameraInfo::iImageFormatsSupported.
It is a bit flag with type CCamera::TFormat.The second parameter of PrepareImageCaptureL() is the indexof the image size. It must be in the range of 0 to (TCameraInfo::iNumImageSizesSupported – 1). You can get all supported image sizes bycalling CCamera::EnumerateCaptureSizes().260SYMBIAN C++ RECIPESFor the sake of simplicity, the discussion in this book focuses only onJPEG (Joint Photographic Expert Group) and EXIF (Exchangeable ImageFile Format) formats. The EXIF format is a specification of an image fileformat used by digital cameras that contains additional metadata tags,such as date and time information, aperture, shutter speed, ISO speedand many more. It is supported by JPEG and some other formats.
It is notsupported by JPEG 2000, PNG and GIF though.What may go wrong when you do this: Before using a format, you haveto make sure that it is supported by the device. For example, most S60devices do not support EFormatJpeg. They support EFormatExif.In order to keep the recipe simple, it uses the synchronous overloadof RFile::Write() to save the captured image. In production code,we recommend that you use the asynchronous method, called using anactive object, to keep the GUI responsive.4.7.3.5Record VideoAmount of time required: 30 minutesLocation of example code: \Multimedia\VideoRecordingRequired libraries: mediaclientvideo.libRequired header file(s): videorecorder.hRequired platform security capability(s): UserEnvironmentProblem: You want to record a video clip from a camera and save it toa file.Solution: Before you continue reading this recipe, make sure that youalready know how to use the CCamera class (see Recipe 4.7.3.2).The class from MMF that is used to record video is CVideoRecorderUtility.
As for many other MMF APIs, there is an observerclass: MVideoRecorderUtilityObserver.The CVideoRecorderUtility class requires UserEnvironmentcapability. There are some methods that require MultimediaDD, butthey will not be discussed in this book.What may go wrong when you do this: There is a known issue on somedevices, which require that applications that perform video recordingpossess the MultimediaDD capability. A good example of this is theNokia N93 and on early firmware of the Nokia N93i. Please check theForum Nokia Technical Library at www.forum.nokia.com for moreinformation.MULTIMEDIA261Using CVideoRecorderUtility is similar to CMdaAudioRecorderUtility, although it is a little more complex.
Here arethe steps required to record a video:• Display the viewfinder using CCamera class (see Recipe 4.7.3.2).• Create an observer that implements MVideoRecorderUtilityObserver.• Create a new instance of CVideoRecorderUtility.• Open the file by calling CVideoRecorderUtility::OpenFileL().• Wait until the observer method, MVideoRecorderUtilityObserver::MvruoOpenComplete(), is called.• Set some configurations, such as audio type.• Call CVideoRecorderUtility::Prepare() to prepare for videorecording.• Wait until the observer method, MVideoRecorderUtilityObserver::MvruoPrepareComplete(), is called.• Call CVideoRecorderUtility::Record() to start recording.• Stop the recording by calling CVideoRecorderUtility::Stop().In our recipe, the CSimpleVideoRecorder class implementsMVideoRecorderUtilityObserver.Discussion: First, let’s take a look at the usage of CVideoRecorderUtility::OpenFileL().
This method requires several parameters, asshown below:IMPORT_C void OpenFileL(const TDesC& aFileName, TInt aCameraHandle,TUid aControllerUid, TUid aVideoFormat,const TDesC8& aVideoType=KNullDesC8,TFourCC aAudioType = KMMFFourCCCodeNULL);The first parameter, aFileName, is the filename to which the videoclip is saved.The aCameraHandle parameter is the handle to the camera touse for recording.
You can get the handle of the camera from theCCamera::Handle() method.The aControllerUid parameter is the UID of the controller to usefor recording. Phone manufacturers provide a controller plug-in to the262SYMBIAN C++ RECIPESMMF, and you must specify the UID of the video controllers in thisparameter. This is different from audio recording, where you don’t needto specify which controller because the audio recorder utility class selectsthe controller automatically based on the file extension.The aVideoFormat parameter is the UID of the video format torecord to, and it depends on the controller plug-in. If you specify a videoformat that is not supported by the controller, you will receive an error.The aVideoType parameter is the descriptor containing the videoMIME type.