Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Camera-enable Your Applications with BREW's ICamera APIs : Page 3

BREW 2.1's ICamera interface allows you to support still and motion image capture from the image sensor found on many of today's mid- and high-end BREW-enabled wireless handsets. Camera-enable your relevant applications by learning how to configure and use this API.


advertisement
Presenting Preview Images
Presenting preview images is the responsibility of your callback function. First, you must place the camera in Preview mode by invoking ICAMERA_Preview:

ICAMERA_Preview( pThis->m_cameraData.pICamera );

Once the camera is in preview mode, ICamera periodically invokes your callback function to let it know that a new bitmap is available to display. A typical callback function might look like this:

static void CameraNotify(void* pUser, AEECameraNotify *pn) { CApp* pThis = (CApp*)pUser; if( !pThis || !pn ) return; switch( pn->nStatus ) { case CAM_STATUS_FRAME: { IBitmap *pFrame = NULL; AEEBitmapInfo bi= {0}; ICAMERA_GetFrame( pThis->pICamera, &pFrame ); if(!pFrame) return; IBITMAP_GetInfo( pFrame, &bi, sizeof(bi)); IDISPLAY_BitBlt(RM_GET_IDISPLAY(pThis), pThis->preview.m_previewRect.x, pThis->preview.m_previewRect.y, bi.cx, bi.cy, pFrame, 0,0, AEE_RO_COPY); // Draw anything over the image you like here. break; } case CAM_STATUS_DONE: … } }

The case we're interested in is the CAM_STATUS_FRAME case; it's the command sent to your callback each time a new frame is available. In turn, your callback must invoke ICAMERA_GetFrame() to obtain an IBitmap containing the captured image from the camera and blit it to the screen using IDISPLAY_BitBlt. While this sounds like a lot of work—and in fact some handsets have an option to do this for you, writing the camera contents directly to the LCD display without your intervention—it offers a lot of flexibility, because you can paint over the preview image, showing camera cross-hairs, UI controls, or the like. You could also come up with some pretty neat effects using the new 3D interfaces, too, with alpha blending and the like.



Capturing Still or Video Images
Capturing still or video images is very similar to preview mode, except that you don’t have to do as much work. What you do have to do, however, is specify the format and maximum size of the resulting file, and place the camera in Record mode. For a snapshot, the code looks like this:

{ // Must be done with a capture command; encode the captured image. int result = 0; AEEMediaData md = {0}; md.clsData = MMD_FILE_NAME; md.pData = pThis->szFileName; md.dwSize = 0; result = ICAMERA_SetMediaData( pThis->pICamera, &md, "image/jpg" ); if( SUCCESS == result ) { // Set the size of this capture result = ICAMERA_SetSize( pThis->pICamera, &pThis->dwCaptureSize); if( SUCCESS == result ) { // dump to the filesystem. result = ICAMERA_RecordSnapshot( pThis->pICamera ); } } }

This is pretty straightforward—the code begins by using the ICAMERA_SetMediaData method to indicate the file name to which the camera should record the image, as well as the desired encoding. Next, it calls ICAMERA_SetSize, which tells the camera the maximum allowable size for the media data in bytes. Once this is done, the code triggers an encoding operation by invoking ICAMERA_RecordSnapshot. If you wanted to make a movie, you could simply call ICAMERA_RecordMovie instead, and call ICAMERA_RecordMovie instead, invoking ICAMERA_Stop when the user wishes to stop recording, or ICAMERA_Pause to pause recording.

Handling Suspend and Resume Events
As you might imagine, the ICamera interface uses a lot of system resources3the image sensor consumes power, and the processor uses power when processing image data and executing the ICamera implementation and your callback. Consequently, your application is best off if it stops the ICamera interface and releases it on a suspend event (EVT_APP_SUSPEND), and re-creates it and resumes its prior state on a resume event. (EVT_APP_RESUME).

The BREW ICamera interface is a simple, asynchronous interface to still and moving image capture on today's mid-range and high-end handsets that provides a great deal of flexibility. Using the ICamera interface, a wide variety of applications are possible. Ineractive games and messaging, content creation (custom wallpapers or ringer IDs), and countless vertical applications can benefit from camera-enabled software.



Ray Rischpater is the chief architect at Rocket Mobile, Inc., specializing in the design and development of messaging and information access applications for today's wireless devices. Ray is the author of several books on software development including "eBay Application Development" and "Software Development for the QUALCOMM BREW Platform," both available from Apress, and is an active amateur radio operator.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date