×

Discussion Board

Results 1 to 9 of 9

Thread: image capturing

  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    Delhi
    Posts
    124

    image capturing

    Hi
    i am using nokia 6303classic S40 6th edition which support JSR234 API,and i am using the following code to capture image, but its not working can anyone explain why..?

    import java.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import javax.microedition.midlet.*;
    import javax.microedition.media.control.*;

    public class CameraMIDlet extends MIDlet implements CommandListener {

    private Display display;
    private Form form,mform;
    private Command exit,back,capture,camera,toCamera;
    private Player player;
    private VideoControl videoControl;
    private Video video;
    public CameraMIDlet() {

    exit = new Command("Exit", Command.EXIT, 0);
    camera = new Command("Camera", Command.SCREEN, 0);
    back = new Command("Back", Command.BACK, 0);
    capture = new Command("Capture", Command.SCREEN, 0);
    toCamera= new Command("Back",Command.BACK,1);
    mform= new Form("Image");
    form = new Form("Capture Video");
    form.addCommand(camera);
    form.addCommand(exit);
    form.setCommandListener(this);
    }

    public void startApp() {
    display = Display.getDisplay(this);
    display.setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable s) {
    if (c == exit) {
    destroyApp(true);
    notifyDestroyed();
    }else if (c == camera) {
    showCamera();
    }else if (c == back){
    display.setCurrent(form);
    }else if (c == capture) {
    video = new Video(this);
    video.start();
    }else if(c==toCamera){
    showCamera();
    }
    }

    public void showCamera() {
    try{
    player = Manager.createPlayer("capture://video");
    player.realize();
    videoControl = (VideoControl)player.getControl("VideoControl");
    Canvas canvas = new VideoCanvas(this, videoControl);
    canvas.addCommand(back);
    canvas.addCommand(capture);
    canvas.setCommandListener(this);
    display.setCurrent(canvas);
    videoControl.setVisible(true);
    player.start();
    }catch (IOException ioe) {
    ioe.printStackTrace();
    }catch (MediaException me) {
    me.printStackTrace();
    }
    }

    class Video extends Thread {
    CameraMIDlet midlet;
    public Video(CameraMIDlet midlet) {
    this.midlet = midlet;
    }

    public void run() {
    captureVideo();

    }

    public void captureVideo() {
    try {
    byte[] raw = videoControl.getSnapshot("encoding=png");
    Image image = Image.createImage(raw, 0, raw.length);
    videoControl.setVisible(false);
    player.stop();
    player.close();
    player = null;
    videoControl = null;
    mform.append(image);
    mform.addCommand(toCamera);
    display.setCurrent(mform);
    mform.setCommandListener(midlet);
    } catch (MediaException me) {
    me.printStackTrace();
    }catch (Exception e) {
    e.printStackTrace();
    }
    }
    };
    }
    //============================

    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.*;

    public class VideoCanvas extends Canvas {
    CameraMIDlet midlet;

    public VideoCanvas(CameraMIDlet midlet, VideoControl videoControl) {
    int width = getWidth();
    int height = getHeight();
    this.midlet = midlet;

    videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
    try {
    videoControl.setDisplayLocation(2, 2);
    videoControl.setDisplaySize(width - 4, height - 4);
    } catch (MediaException me) {
    me.printStackTrace();
    }

    }

    public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();

    g.setColor(0x00ff00);
    g.drawRect(0, 0, width - 1, height - 1);
    g.drawRect(1, 1, width - 3, height - 3);
    }
    }

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: image capturing

    Quote Originally Posted by bejoy_ak View Post
    its not working
    Can you be any more specific?

    Quote Originally Posted by bejoy_ak View Post
    byte[] raw = videoControl.getSnapshot("encoding=png");
    My first suspicion would be that this might not be supported.

    Graham.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    Delhi
    Posts
    124

    Re: image capturing

    i replaced that by this then also no result..its showing the camera but nothing happens when i press the capture button...


    byte[] raw = videoControl.getSnapshot(null);

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: image capturing


  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    Delhi
    Posts
    124

    Re: image capturing

    the same code worked in N95....i don't know what is the problem with 6303...

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: image capturing

    It is not necessarily a problem with the 6303. Different phones behave differently. This is normal. Especially phones of different operating systems. You will find it often the case that problems in your code will show up on some devices, and not on others.

    Is any exception being thrown?

    Try the sample code. Does that work? If so, see how the sample code is different to yours.

    Graham.

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    Delhi
    Posts
    124

    Re: image capturing

    i tried the sample code you provided..its showing the error

    "Only capture://image locator supports getSnapshot()"

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: image capturing

    Does this work?

    PHP Code:
    import java.io.IOException;

    import javax.microedition.midlet.MIDlet;

    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;

    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.control.VideoControl;

    public class 
    Snapper extends MIDlet implements CommandListener {
        private static final 
    Command EXIT = new Command("Exit"Command.EXIT, 0);
        private static final 
    Command SNAP = new Command("Snap"Command.OK0);

        private 
    Displayable shown;

        public 
    void startApp() {
            if (
    shown == null) {
                
    shown = new ViewFinder();
                
    shown.addCommand(SNAP);

                try {
                    ((
    ViewFindershown).initialize();
                } catch (
    Exception e) {
                    
    Form f = new Form("Error");
                    
    f.append(e.toString());
                    
    shown f;
                }
                
    shown.addCommand(EXIT);
                
    shown.setCommandListener(this);
            }
            
    setCurrent(shown);
        }

        public 
    void pauseApp() {
            
    // do nothing
        
    }

        public 
    void destroyApp(boolean must) {
            
    // do nothing
        
    }

        private 
    void setCurrent(Displayable d) {
            
    shown d;
            
    Display.getDisplay(this).setCurrent(d);
        }

        public 
    void commandAction(Command cDisplayable d) {
            if (
    == EXIT) {
                
    notifyDestroyed();
            } else if (
    == SNAP) {
                
    Form f;
                try {
                    
    byte[] image = ((ViewFinderd).snap();
                    
    = new Form("Success");
                    
    f.append(Image.createImage(image0image.length));
                } catch (
    Exception e) {
                    
    = new Form("Error");
                    
    f.append(e.toString());
                }
                
    f.addCommand(EXIT);
                
    f.setCommandListener(this);
                
    setCurrent(f);
            }
        }

        private static class 
    ViewFinder extends Canvas {
            private 
    Player player;
            private 
    VideoControl video;

            public 
    void initialize() throws MediaExceptionIOException {
                
    player Manager.createPlayer("capture://image");
                
    player.start();
                
    video = (VideoControlplayer.getControl("VideoControl");
                
    video.initDisplayMode(VideoControl.USE_DIRECT_VIDEOthis);
                
    video.setDisplayLocation(22);
                
    video.setDisplaySize(getWidth() - 4getHeight() - 4);
                
    video.setVisible(true);
            }

            public 
    byte[] snap() throws MediaException {
                
    byte[] data video.getSnapshot(null);
                
    player.stop();
                return 
    data;
            }

            protected 
    void paint(Graphics g) {
                
    g.setColor(0xffffff);
                
    g.fillRect(00getWidth(), getHeight());
            }
        }


  9. #9
    Registered User
    Join Date
    Oct 2009
    Location
    Delhi
    Posts
    124

    Re: image capturing

    thanks graham sir

    it worked....

Similar Threads

  1. Capturing an image on Nokia 3230?
    By sunil_bhambani123 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2008-09-24, 19:34
  2. Capturing image from secondary camera problem
    By michaelnewyork in forum Symbian
    Replies: 7
    Last Post: 2008-09-08, 08:09
  3. Capturing a greyscale Image / Recoding a JPEG
    By -chris- in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2008-07-23, 20:26
  4. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  5. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×