Results 1 to 5 of 5

Thread: J2ME code for capture of photos and pictures in mobile

  1. #1
    Join Date
    Sep 2010
    Posts
    19

    J2ME code for capture of photos and pictures in mobile

    I am willing to know how you can capture images from the camera of the terminal and how you can display on a screen Canvas. I have used J2ME code to some extent (can say pretty much ), and now I have turned to do some mobile coding. I want your help in code that can be useful when capturing photos and pictures. It would be much grateful, if you provide some sample of code along with the information. [code makes easy to understand].. Please help me..

  2. #2
    Join Date
    Jan 2009
    Posts
    92

    Re: J2ME code for capture of photos and pictures in mobile

    In creating the project, using the WTK, you must remember to select the row for Mobile Media API (JSR 135) on the "Settings for Project". To verify the support of the capture of images from the camera, you can use the method getProperty() of class System . This method, using as the key parameter that identifies the features to be verified, provide a way to know the capabilities of our phone and certain applications can be performed to determine whether or not a particular model. The method getProperty returns a string if the property is supported, null vice versa.

  3. #3
    Join Date
    Mar 2008
    Posts
    232

    Re: J2ME code for capture of photos and pictures in mobile

    The method getProperty returns a string if the property is supported, null vice versa.
    In this case, the property to check is video.snapshot.encodings that allows us to detect a string that lists the encodings of the images captured by the camera and obviously we get a null if the terminal does not support Camera:
    Code:
    String value = System.getProperty ("video.snapshot.encodings"); 
    System.out.println ("Encodings capture:" + value);
    Executing the code in WTK, the result we get is the string "encoding=jpeg encoding=png" , which means that we can capture images in jpg encoding both in PNG. If the string that is returned is null, we can see you indicating the lack of capture of pictures on the phone.
    Code:
    Alert alert = new Alert ("Unlucky, but your terminal does not support the capture of photo); 
    display.setCurrent (alert);

  4. #4
    Join Date
    Apr 2008
    Posts
    193

    Re: J2ME code for capture of photos and pictures in mobile

    If the previous test was successful, you can proceed to create the interface that allows you to take the picture. The method buildPlayer class PhotoCanvas usually initializes the object Player, but using "capture" as the protocol for the method createPlayer().
    Code:
    .. / / 
    public void buildPlayer () 
    { 
    try 
    { 
    Manager.createPlayer player = ("capture: / / video"); 
    player.realize (); 
    vc = (VideoControl) (player.getControl (VideoControl ")); 
    if (vc == null) 
    { 
    / / The videocontrol can not be created. 
    throw new MediaException ("Video control not supported"); 
    } 
    else 
    { 
    vc.initDisplayMode (VideoControl.USE_DIRECT_VIDEO, this); 
    
    vcWidth vc.getDisplayWidth = int (); 
    vcHeight vc.getDisplayHeight = int (); 
    
    int x = (canvasWidth - vcWidth) / 2; 
    int y = (canvasHeight - vcHeight) / 2; 
    
    vc.setDisplayLocation (x, y); 
    } 
    } 
    ....//
    From the main midlet object is created PhotoCanvas and then start the player by calling startPlayer() , which uses a Boolean variable to see if the player is not already active (this is useful for restarting the player after it has captured image).
    Code:
    public void startPlayer () 
    { 
    if (! playerActive) 
    { 
    try 
    { 
    if (imageCaptured! = null) 
    { 
    imageCaptured = null; 
    if (back! = null) 
    { 
    removeCommand (back); 
    } 
    } 
    if (player! = null) 
    { 
    player.start (); 
    } 
    if (vc! = null) 
    { 
    vc.setVisible (true); 
    } 
    playerActive = true; 
    } 
    catch (MediaException s) 
    { 
    e.printStackTrace (); 
    } 
    } 
    }
    WTK does not exist in a capture device such as in camera phones, so when you start the application, the emulator will display a separate screen into rectangles that move from right to left.

  5. #5
    Join Date
    Jan 2006
    Posts
    211

    Re: J2ME code for capture of photos and pictures in mobile

    To take the photo using the pointer to the terminal: thus we provide the overriding keyPressed the Canvas class as follows:
    Code:
    protected void keyPressed (int key) 
    { 
    super.keyPressed (key); 
    if (getGameAction (key) == Canvas.FIRE) 
    { 
    SnapshotCapturer SnapshotCapturer capturer = new (); 
    capturer.start (); 
    } 
    }
    Like the operation of network connection, it is appropriate to make an image capture operation in a separate thread so as not to block the long-midlet: in this case we use the object SnapshotCapturer defined inside the class PhotoCanvas :
    Code:
    SnapshotCapturer class extends Thread 
    { 
    public void run () 
    { 
    byte [] photo; 
    try 
    { 
    vc.getSnapshot photo = (null); 
    fotodemo.showCapturedPhoto (photo); 
    } 
    catch (MediaException s) 
    { 
    // TODO Auto-generated catch block 
    e.printStackTrace (); 
    } 
    } 
    }

Similar Threads

  1. Only old pictures are shown in WD Photos app
    By Mitchell-Y in forum Hardware Peripherals
    Replies: 4
    Last Post: 22-06-2012, 06:30 PM
  2. Replies: 10
    Last Post: 15-11-2011, 10:48 AM
  3. need J2me source code for camera snapshot module
    By HoST in forum Windows Software
    Replies: 2
    Last Post: 11-01-2010, 01:38 PM
  4. developing a 2D mobile game in J2ME
    By Aramax in forum Software Development
    Replies: 3
    Last Post: 21-09-2009, 02:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,293,083.24327 seconds with 17 queries