v980 e1000 camera capture (1)

5
 November 23, 2004 Image Capture in V980/E1000 WHITE PAPER

Upload: varaprasady

Post on 06-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: V980 E1000 Camera Capture (1)

8/3/2019 V980 E1000 Camera Capture (1)

http://slidepdf.com/reader/full/v980-e1000-camera-capture-1 1/5

November 23, 2004

Image Capture in V980/E1000

WHITE PAPER

Page 2: V980 E1000 Camera Capture (1)

8/3/2019 V980 E1000 Camera Capture (1)

http://slidepdf.com/reader/full/v980-e1000-camera-capture-1 2/5

Image Capture in V980/E1000By

Motocoder Staff

How do you capture an image from your J2ME application? The newly released CLDC1.1 basedhandsets like V980 and E1000 support the capture of displayed video on the phone’s screen from theapplication using the Mobile Media API [1]. This newsletter describes the various steps of capturing animage from a J2ME application. Capturing an image from an application involves three steps. Firstly,displaying the video on a canvas or a form; secondly, taking the snapshot of the displayed image; thirdlysaving the captured image. In this newsletter we will first go through each of these steps (highlightingthe API methods involved), then we will give brief description of the sample application, implementing

image capture and finally we will highlight the steps for taking the snapshot using the attached sampleapplications and possible issues that a user may encounter. The complete source code for the sampleapplications along with jar and jad is attached in a separate zip file as well.

Video Display on Canvas or Form The video feed from the camera can be feed to the canvas or form so that user can see the picture of what he is going to take snapshot. Following operations are involved in displaying the video on thecanvas or form.

1) Creation of player object for obtaining the VideoControl object.

Player p = Manager.createPlayer("capture://video");2) Obtaining the video control object from the player object, for capturing video.

VideoControl vc = (VideoControl)p.getControl("VideoControl");3) Video can be displayed in two modes- USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE.

USE_DIRECT_VIDEO is used for displaying the video directly on canvas.USE_GUI_PRIMITIVE mode is used to obtain the GUI primitive (Item), where the GUI of video control will be displayed. These modes are initialized by using the initDislayMode() of GUIControl.

a. For displaying the video on the canvas:

vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this); // this refers to

the current instance of the canvas object.b. For displaying video on the form:

frm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));//frmrefers to the form in use.

4) After setting the appropriate size of display for video, the player can be started.

vc.setDisplayFullScreen(true); //setting the display are for video to befull screen.

Page 3: V980 E1000 Camera Capture (1)

8/3/2019 V980 E1000 Camera Capture (1)

http://slidepdf.com/reader/full/v980-e1000-camera-capture-1 3/5

vc.setVisible(true); //Used only if the mode to display the video isUSE_DIRECT_VIDEO.

p.start(); //starting the player

Snapshot of the Image The snapshot of the displayed image on canvas/form can be taken by using the getSnapshot(StringimageType) method of VideoControl. This method returns a byte array containing the snapshot of thecaptured image in the feature and format defined by the imageType parameter of getSnapshot(). Thesupported image formats for the getSnapshot() can be obtained from the System.getProperty() withvideo.snapshot.encodings as key. If null is specified for imageType the default features and formatsare used (encoding=jpeg&width=176&height=144) . At present the various values of imageTypesupported by the V980 and E1000 are-

• encoding=jpeg&width=160&height=120• encoding=jpeg&width=176&height=144• encoding=jpeg&width=320&height=240• encoding=jpeg&width=640&height=480• encoding=jpeg&width=1280&height=960(not supported in V980).

Saving the Captured Image

The byte array obtained from the getSnapshot() needs to be saved. The easiest way to save this array isto transfer this byte array containing image to the PC from the serial port and have a serial port listenerapplication listening on the serial port. Following steps are involved in transferring the image to PC :

1) Obtaining the CommConnection Object: This is achieved by opening the CommConnection:

CommConnection commConn = (CommConnection)Connector.open("comm:" + port +baudrate); //The baudrate used for transfer should be same as the baudrateof the receiving application running on PC and port should be same serialport on which the application is listening.

2) Transferring the Image to PC: After serial port connection has opened successfully, the capturedimage can be transferred to PC, by writing the image byte array to the output stream. Beforetransferring the byte array, the receiving application should be started. The listener applicationon PC can use the Java Communication APIs [2] for receiving the image data. On receiving theimage data from the J2ME application, the listener will know about it and it can read from inputstream the image data and use this data to create an image file, representing the capture imagefrom the phone.

Image Capture Sample Applications

There are three sample applications- two of them are the midlet suites one having the Canvas asdisplayable (ImageCaptureCanvasSuite) and another having the form as displayable(ImageCaptureFormSuite). Please note that both of these midlet suites provide the same functionality of

Page 4: V980 E1000 Camera Capture (1)

8/3/2019 V980 E1000 Camera Capture (1)

http://slidepdf.com/reader/full/v980-e1000-camera-capture-1 4/5

capturing image and sending the captured data to PC. The third sample application is a J2SE basedapplication (SerialPortRead.java) for receiving the captured image, send by ImageCaptureCanvasSuiteor ImageCaptureFormSuite.

1) ImageCaptureCanvasSuite: This midlet suite contains ImageCaptureCanvasMIDlet midlet andImageCaptureCanvas class. ImageCaptureCanvas extends the Canvas class and provides thefunctionality of- displaying the video on a canvas, capturing the image from displayed video andtransferring the image data to PC. The ImageCaptureCanvasMIDlet displays theImageCaptureCanvas object.

2) ImageCaptureFormSuite: This midlet suite contains ImageCaptureFormMIDlet midlet.ImageCaptureFormMIDlet provides the functionality of- displaying the video on a form,capturing and and transferring the image data to PC.

3) SerialPortRead: This is a J2SE based application. It receives the image data send by theImageCaptureCanvas or ImageCaptureForm and saves the image data as a jpeg file on the PC. Inorder to compile the source file (SerialPortRead.java) the Java Communication API needs to bedownloaded. The Java communication API can be downloaded and installed from:http://java.sun.com/products/javacomm/downloads/index.html . Please follow the appropriateinstallation instructions, available with the API.

The above mentioned applications (ImageCaptureCanvasSuite, ImageCaptureFormSuite andSerialPortRead) are present as part of attached zip file (ImageCapture.zip). The jar, jad and source codeof the applications are organized in the following hierarchy:Sample Application-1(ImageCaptureCanvasSuite)

1) ImageCaptureCanvasSuite.jad-- imagecapture/canvas2) ImageCaptureCanvasSuite.jar-- imagecapture/canvas3) ImageCaptureMIDlet.java-- imagecapture/canvas4) ImageCaptureCanvas.java-- imagecapture/canvas

Sample Application-2(ImageCaptureFormSuite)1) ImageCaptureFormSuite.jad-- imagecapture/form2) ImageCaptureFormSuite.jar-- imagecapture/form3) ImageCaptureFormMIDlet.java-- imagecapture/form

SampleApplication-3(SerialPortRead)1) SerialPortRead.java-- imagecapture/pcapplication2) SerialPortRead.class-- imagecapture/pcapplication

Taking the snapshot using the Sample Applications

1) Initially the image capture application will be in the video display mode. Once the image to becaptured is selected, press CAPTURE to take snapshot.

2) Press OK (after selecting the appropriate option) on the screen asking you that if you want to

Start Recording.3) Press SAVE to save the captured image.4) Unplug the RS 232 cable from your phone, if it is connected. Then press OPEN to open serial

port connection with PC.5) Press OK on the screen that asks you for making a local connection on COM1 port.6) Start the SerialPortRead application on your PC.7) Plug the RS 232 cable to phone (the cable should connect to PC on COM1 port at one end and

phone on other end).

Page 5: V980 E1000 Camera Capture (1)

8/3/2019 V980 E1000 Camera Capture (1)

http://slidepdf.com/reader/full/v980-e1000-camera-capture-1 5/5

8) Once the image has completely transferred to PC, press BACK to again start the image capture

or press EXIT to exit from the image capture application.

Possible Issues in Using the Sample Applications

• Issue: No display appears on the form based application.• Solution: Press the down navigation key so that display can appear.• Issue: Application hangs while pressing the transfer• Solution: Try to unplug the RS232 cable and again connect it firmly to the phone.

Conclusion In this newsletter we have covered the various steps for taking the snapshot from a J2ME application and savingthe captured image to PC. We have also presented the sample applications along with the source code to take thesnap shot.

References 1) Mobile Media API (JSR135) version 1.1.

2) Java Communications API http://java.sun.com/products/javacomm/index.jsp .