Академический Документы
Профессиональный Документы
Культура Документы
WHITE PAPER
How do you capture an image from your J2ME application? The newly released CLDC1.1 based handsets like V980 and E1000 support the capture of displayed video on the phones screen from the application using the Mobile Media API [1]. This newsletter describes the various steps of capturing an image 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; thirdly saving the captured image. In this newsletter we will first go through each of these steps (highlighting the 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 sample applications and possible issues that a user may encounter. The complete source code for the sample applications along with jar and jad is attached in a separate zip file as well.
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.
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 be full screen.
vc.setVisible(true); //Used only if the mode to display the video is USE_DIRECT_VIDEO. p.start(); //starting the player
2) Transferring the Image to PC: After serial port connection has opened successfully, the captured image can be transferred to PC, by writing the image byte array to the output stream. Before transferring the byte array, the receiving application should be started. The listener application on PC can use the Java Communication APIs [2] for receiving the image data. On receiving the image data from the J2ME application, the listener will know about it and it can read from input stream the image data and use this data to create an image file, representing the capture image from the phone.
capturing image and sending the captured data to PC. The third sample application is a J2SE based application (SerialPortRead.java) for receiving the captured image, send by ImageCaptureCanvasSuite or ImageCaptureFormSuite. 1) ImageCaptureCanvasSuite: This midlet suite contains ImageCaptureCanvasMIDlet midlet and ImageCaptureCanvas class. ImageCaptureCanvas extends the Canvas class and provides the functionality of- displaying the video on a canvas, capturing the image from displayed video and transferring the image data to PC. The ImageCaptureCanvasMIDlet displays the ImageCaptureCanvas 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 the ImageCaptureCanvas or ImageCaptureForm and saves the image data as a jpeg file on the PC. In order to compile the source file (SerialPortRead.java) the Java Communication API needs to be downloaded. The Java communication API can be downloaded and installed from: http://java.sun.com/products/javacomm/downloads/index.html. Please follow the appropriate installation instructions, available with the API. The above mentioned applications (ImageCaptureCanvasSuite, ImageCaptureFormSuite and SerialPortRead) are present as part of attached zip file (ImageCapture.zip). The jar, jad and source code of the applications are organized in the following hierarchy: Sample Application-1(ImageCaptureCanvasSuite) 1) ImageCaptureCanvasSuite.jad-- imagecapture/canvas 2) ImageCaptureCanvasSuite.jar-- imagecapture/canvas 3) ImageCaptureMIDlet.java-- imagecapture/canvas 4) ImageCaptureCanvas.java-- imagecapture/canvas Sample Application-2(ImageCaptureFormSuite) 1) ImageCaptureFormSuite.jad-- imagecapture/form 2) ImageCaptureFormSuite.jar-- imagecapture/form 3) ImageCaptureFormMIDlet.java-- imagecapture/form SampleApplication-3(SerialPortRead) 1) SerialPortRead.java-- imagecapture/pcapplication 2) SerialPortRead.class-- imagecapture/pcapplication
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 saving the captured image to PC. We have also presented the sample applications along with the source code to take the snap shot.
References
1) Mobile Media API (JSR135) version 1.1. 2) Java Communications API http://java.sun.com/products/javacomm/index.jsp.