×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    13

    jsr234 camera getSnapShot() on Nokia N95

    Hi,

    Just wondering if jsr234 camera getSnapShot() is supported on the Nokia N95.

    From what I can tell it is not ?

    I have tried a jsr234 camera example from sun in wireless toolkit 2.5 on the N95 and only get the video preview screen and an exit button - nothing else, due to null returned for all of the camera control requests...

    I note that Nokia's pdf on jsr234 only discusses the audio capabilities.

    Support for jsr135 seems pretty poor as well with best camera snapshot resolution I can get to work being 480x640.

    On a device with native 5mp camera this is disappointing, particularly with Nokia doing the submission for jsr234...

    Any comments / help / suggestions appreciated.

    Thanks

    (PS this is my 1st post, let me know if I'm asking in the wrong area)

  2. #2
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: jsr234 camera getSnapShot() on Nokia N95

    Welcome to the FN discussion boards!

    N95 (and S60 3rd Edition FP1 devices) supports a number of audio related controls from the AMMS API. The image/video related packages are not implemented on this platform.

    Hartti

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    13

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi,

    Many thanks for your quick reply, I guess I will have to use the native S60 c++ platform to access the N95 camera capabilities.

    I see that the provided 2D Barcode reader program has good access to the camera features so there is hope for my intended development.

    Regards

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    53

    Re: jsr234 camera getSnapShot() on Nokia N95

    Best resolution youve gotten is 640*480? I dont know what youve been doing, I just took 1024*768 with "encoding=jpeg&width=1024&height=768" and it worked fine.

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    13

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi,

    re: Best resolution youve gotten is 640*480? I dont know what youve been doing, I just took 1024*768 with "encoding=jpeg&width=1024&height=768" and it worked fine.

    I have tried, what you suggested and other's similar previously (for jsr135) & I consistently get a javax.microedition.media.MediaException: Symbian OS error: -4.

    - for resolution greater than 640x480

    eg: "encoding=JPEG&width=480&height=640" does work ok

    If I use "encoding=JPEG&width=640&height=480" it does not work.

    I cannot find what the Symbian error -4 means so far.

    The encoding types I get back from the camera are in uppercase eg: encoding=JPEG

    I will persevere with variations of what you have suggested and post back the results in detail.

    My N95 software version is 10.0.018 15/03/07.

    Thanks & regards

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    53

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hmm here are the keyparts of my code I used:

    Code:
    playa=Manager.createPlayer("capture://video"); 
    playa.realize();
    ...
    vc=(VideoControl)playa.getControl("VideoControl");
    ...
    enc="encoding=jpeg&width=1024&height=768";
    imgBytes = vc.getSnapshot(enc);
    Are they different than yours?

  7. #7
    Registered User
    Join Date
    May 2007
    Posts
    13

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi,

    I have coded up the Nokia jsr135 example - CameraMIDlet

    and have tried using -

    // byte[] pngImage = videoControl.getSnapshot(null); // default w=640, h=480 - works ok !

    // byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=1024&height=768"); NBG

    // byte[] pngImage = videoControl.getSnapshot("encoding=png&width=1024&height=768"); NBG

    // byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=640&height=480"); OK

    // byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=1280&height=960"); NBG

    I am still only able to get the default encoding (null) and one explicit encoding "encoding=jpeg&width=640&height=480" to work so far.

    (my previous comment about uppercase - "encoding=JPEG" was incorrect - that is Sony w810i related)

    I suspect that "encoding=jpeg&width=1024&height=768" might be working sometimes but failing when creating the image from the raw bytes using -

    Image image=Image.createImage(pngImage,0,pngImage.length);

    -perhaps using too much memory, but I haven't caught any exceptions for this yet...

    The behaviour when using "encoding=jpeg&width=1024&height=768" is after taking snapshot the (yellow) video preview window continues to be displayed, rather than switching to the (cyan) snapshot image display window.

    If "encoding=jpeg&width=1024&height=768" is working for you on N95 are you able to create the image successfully from the byte array returned from getSnapShot() call & preview ok ?

    I will keep trying & let you know of any sucess.

    Many thanks for responding.

    Regards

  8. #8
    Registered User
    Join Date
    Mar 2007
    Posts
    53

    Re: jsr234 camera getSnapShot() on Nokia N95

    My app can create image from returned byte array with Image.createImage-method when using 1024*768. Are you running any other programs while testing your app on n95? Have you replicated the nokia example exactly? You sure you are using capture://video and not some other? I looked up that Nokia Camera from january 24 2003, is this the one you have based your code on?

  9. #9
    Registered User
    Join Date
    May 2007
    Posts
    13

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi,

    In general I am not running any other programs.

    I have tried turning phone off & on again but get same results as mentioned for -

    videoControl.getSnapshot("encoding=jpeg&width=1024&height=768");

    There is no 'task manager' so I cannot be sure of other programs running.

    I have also tried upgrading N95 phone rom ( now V11.0.026 ) but get same results.

    The CameraMIDlet I am using is coded (exactly) from the the Nokia Example from 24 Jan 2003. I have drawn 2 string, in the paint method, to show the width & height of the image, but that is the only changes...

    The only thing I am possibly doing differently is using Netbeans V5.5 IDE with JSE V1.5.11 and Java ME wireless toolkit V2.5. I am not using Eclipse with Carbibe J as yet, but I don't think this should make any difference anyway?

    I have also tried Netbeans V4.1 with JSE 1.4.2.8 but get same results.

    I have pasted the source code following (I hope that it appropriate for the forum)

    Again many thanks, for your replies,

    I will try with Eclipse + Carbide J etc & let you know how it goes.

    Regards

    /////////////////////////////////////// Start

    /*
    * CameraMidlet.java
    *
    * Created on 21 May 2007, 13:22
    */

    //unnamedpackage

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;


    //unnamedpackage
    // import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.*;
    import java.io.IOException;

    public class CameraMidlet extends MIDlet
    {
    private CameraCanvas cameraCanvas=null;
    private DisplayCanvas displayCanvas=null;

    public CameraMidlet()
    {}

    public void startApp()
    {
    Displayable current=Display.getDisplay(this).getCurrent();

    if (current==null)
    {
    //firstcall

    cameraCanvas = new CameraCanvas(this);
    displayCanvas = new DisplayCanvas(this);
    Display.getDisplay(this).setCurrent(cameraCanvas);
    cameraCanvas.start();
    }
    else
    {
    //returningfrompauseApp
    if (current==cameraCanvas)
    {
    cameraCanvas.start();
    }

    Display.getDisplay(this).setCurrent(current);
    }

    }

    public void pauseApp()
    {
    if (Display.getDisplay(this).getCurrent()==cameraCanvas)
    {
    cameraCanvas.stop();
    }
    }

    public void destroyApp(boolean unconditional)
    {
    if (Display.getDisplay(this).getCurrent()==cameraCanvas)
    {
    cameraCanvas.stop();
    }
    }

    private void exitRequested()
    {
    destroyApp(false);
    notifyDestroyed();
    }

    void cameraCanvasExit()
    {
    exitRequested();
    }

    void cameraCanvasCaptured(byte[]pngData)
    {
    cameraCanvas.stop();
    displayCanvas.setImage(pngData);
    Display.getDisplay(this).setCurrent(displayCanvas);
    }

    void displayCanvasBack()
    {
    Display.getDisplay(this).setCurrent(cameraCanvas);
    cameraCanvas.start();
    }

    }

    ////////////////////////////////////////////////////////////

    class CameraCanvas extends Canvas implements CommandListener
    {
    private final CameraMidlet midlet;

    private final Command exitCommand;

    private Command captureCommand=null;

    private Player player=null;
    private VideoControl videoControl=null;

    private boolean active=false;

    //Two strings for displaying errormessages

    private String message1=null;
    private String message2=null;

    public CameraCanvas(CameraMidlet midlet)
    {
    this.midlet=midlet;

    exitCommand = new Command("Exit",Command.EXIT,1);

    addCommand(exitCommand);

    setCommandListener(this);

    try
    {
    player=Manager.createPlayer("capture://video");

    player.realize();

    //Grab the videocontrol and set it to the current display.

    videoControl=(VideoControl)(player.getControl("VideoControl"));

    if (videoControl==null)
    {
    discardPlayer();
    message1="Unsupported:";
    message2="Can't get videocontrol";
    }
    else
    {
    videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this);

    //centrevideo,letting it be clipped if it's too big

    int canvasWidth=getWidth();
    int canvasHeight=getHeight();

    int displayWidth=videoControl.getDisplayWidth();
    int displayHeight=videoControl.getDisplayHeight();

    int x=(canvasWidth-displayWidth)/2;
    int y=(canvasHeight-displayHeight)/2;

    videoControl.setDisplayLocation(x,y);

    captureCommand = new Command("Capture",Command.SCREEN,1);

    addCommand(captureCommand);

    }

    }catch(IOException ioe)
    {
    discardPlayer();

    message1="IOException:";
    message2=ioe.getMessage();

    } catch(MediaException me)
    {
    discardPlayer();

    message1="MediaException:";
    message2=me.getMessage();
    } catch(SecurityException se)
    {
    discardPlayer();

    message1="SecurityException";
    message2=se.getMessage();
    }

    }

    //Called in case of exception to make sure invalid players are closed

    private void discardPlayer()
    {
    if(player!=null)
    {
    player.close();
    player=null;
    }

    videoControl=null;
    }

    public void paint(Graphics g)
    {
    g.setColor(0x00FFFF00); //yellow

    g.fillRect(0,0,getWidth(),getHeight());

    if (message1!=null)
    {
    g.setColor(0x00000000);//black

    g.drawString(message1,1,1,Graphics.TOP|Graphics.LEFT);

    g.drawString(message2,1,1+g.getFont().getHeight(),Graphics.TOP|Graphics.LEFT);

    }

    }

    synchronized void start()
    {

    if((player!=null)&&!active)
    {
    try
    {
    player.start();
    videoControl.setVisible(true);
    }
    catch(MediaException me)
    {
    message1 = "Mediaexception:";
    message2 = me.getMessage();
    }
    catch(SecurityException se)
    {
    message1="SecurityException";
    message2=se.getMessage();
    }

    active=true;

    }

    }

    synchronized void stop()
    {
    if((player!=null)&&active)
    {
    try
    {
    videoControl.setVisible(false);
    player.stop();
    }
    catch(MediaException me)
    {
    message1="MediaException:";
    message2=me.getMessage();
    }
    active=false;
    }
    }

    public void commandAction(Command c,Displayable d)
    {
    if(c==exitCommand)
    {
    midlet.cameraCanvasExit();
    }
    else if(c==captureCommand)
    {
    takeSnapshot();
    }
    }

    public void keyPressed(int keyCode)
    {
    if(getGameAction(keyCode)==FIRE)
    {
    takeSnapshot();
    }

    }

    private void takeSnapshot()
    {
    if(player!=null)
    {
    try
    {

    // encoding=jpeg&width=1024&height=768

    // byte[] pngImage = videoControl.getSnapshot(null); // default w=640, h=480 - works ok !

    byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=1024&height=768"); //NBG

    // byte[] pngImage = videoControl.getSnapshot("encoding=png&width=1024&height=768"); NBG

    // byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=640&height=480"); OK

    // byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=1280&height=960"); NBG


    midlet.cameraCanvasCaptured(pngImage);
    }
    catch(MediaException me)
    {
    message1="MediaException:";
    message2=me.getMessage();
    }
    catch(Exception e)
    {
    message1="Exception:";
    message2=e.getMessage();
    }

    }

    }

    }

    ////////////////////////////////////////////////////////////

    class DisplayCanvas extends Canvas implements CommandListener
    {

    private final CameraMidlet midlet;
    private Image image=null;

    public DisplayCanvas(CameraMidlet midlet)
    {
    this.midlet=midlet;

    addCommand(new Command("Back",Command.BACK,1));

    setCommandListener(this);
    }

    public void paint(Graphics g)
    {
    g.setColor(0x0000FFFF);//cyan
    g.fillRect(0,0,getWidth(),getHeight());
    if (image!=null)
    {
    g.drawImage(image,getWidth()/2,getHeight()/2,Graphics.VCENTER|Graphics.HCENTER);

    g.setColor(0x00000000);//black

    g.drawString( "width=" + image.getWidth(), 1,1,Graphics.TOP|Graphics.LEFT);

    g.drawString( "height=" + image.getHeight() ,1,1+g.getFont().getHeight(),Graphics.TOP|Graphics.LEFT);
    }
    }

    void setImage(byte[]pngImage)
    {

    image=Image.createImage(pngImage,0,pngImage.length);
    }

    public void commandAction(Command c,Displayable d)
    {
    midlet.displayCanvasBack();
    }

    }

    ////////////////////////////////////// End

  10. #10
    Registered User
    Join Date
    May 2007
    Posts
    13

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi,

    I have managed to get the following higher resolutions to work ok on my N95 -

    byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=720&height=576"); // YES OK!!!

    byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=896&height=672"); // YES OK !!!

    (these may be just rescaled from 640x480 as they appear a bit blurry)

    I cannot get anything higher than 896x672 eg -

    byte[] pngImage = videoControl.getSnapshot("encoding=jpeg&width=960&height=720"); // NBG

    But I am happy to do better than 640 x 480.

    Thanks for the assistance.

    Regards

  11. #11
    Registered User
    Join Date
    Mar 2007
    Posts
    53

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hmm, try setting videoControl.setVisible(false); just before taking the snapshot. I have it and I have vague memory it mightve had something to do with this problem.

  12. #12
    Registered User
    Join Date
    May 2007
    Posts
    13

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi,

    I tried setting VideoControl.setVisible(false); as suggested and that enabled me to get up to VideoControl.getSnapshot("encoding=jpeg&width=960&height=720");

    which is great, but still could not achieve 1024x768 after many attempts.

    Many thanks again, this is much better than my original 640x480.

    Regards

  13. #13
    Registered User
    Join Date
    Mar 2007
    Posts
    53

    Re: jsr234 camera getSnapShot() on Nokia N95

    Okay, I wrote small program that I tested and found working that took those pics at 1024*768 on n95. If it still doesnt work, Im puzzled and you might want to ask from some nokia experts what the deal is (is there different hardware in some models in some areas etc) Here is the code:

    MainMidlet.java
    Code:
    package pictest;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    /**
     *
     * @author  JDoe
     * @version
     */
    public class MainMidlet extends MIDlet {
        public void startApp() {
            new PicCap(this);
        }
        
        public void pauseApp() {
        }
        
        public void destroyApp(boolean unconditional) {
        }
    }
    PicCap.java
    Code:
    package pictest;
    
    
    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.*;
    
    /**
     *
     * @author JDoe
     */
    public class PicCap implements Runnable,CommandListener{
        
        private MainMidlet parent;
        private Display disp;
        private Image img=null;
        
        private Player player=null;
        private VideoControl vc=null;
        
        private Command cmdSnap,cmdExit;
        
        private boolean error=false;
        private String errormsg="";
        
        /** Creates a new instance of PicCap */
        public PicCap(MainMidlet m) {
            disp=Display.getDisplay(m);
            parent=m;
            cmdSnap=new Command("Snap",Command.OK,0);
            cmdExit=new Command("Exit",Command.EXIT,0);
            initCam();
            if (error==true){
               showErrors();
            }
        }
        
        
        public void run(){
            ohSnap();
             if (error==true){
             showErrors();
            }else {
            showSnap();
            }
        }
        private void showErrors(){
            Form f=new Form("Errors");
                f.addCommand(cmdExit);
                f.setCommandListener(this);
                f.append(errormsg);
                disp.setCurrent(f);
        }
        public void commandAction(Command c, Displayable displayable) {
            
            if (c==cmdSnap){
                Thread t=new Thread(this);
                t.start();
            }else if (c==cmdExit){
                parent.destroyApp(false);
                parent.notifyDestroyed();
            }
            
        }
        private void initCam(){
            try {
                player=Manager.createPlayer("capture://video");
                player.realize();
            }catch (Exception e){
                
                try {
                    player=Manager.createPlayer("capture://devcam0");
                    player.realize();
                }catch (Exception e2){
                    error=true;
                    errormsg+=e2.getMessage();
                }
                
            }
            
            vc=(VideoControl)player.getControl("VideoControl");
            
            if (vc==null){
                error=true;
                return;
            }
            Item item=(Item)vc.initDisplayMode(
                    GUIControl.USE_GUI_PRIMITIVE,null );
            
            Form f=new Form("CamForm");
            f.setCommandListener(this);
            f.addCommand(cmdSnap);
            f.addCommand(cmdExit);
            f.append(item);
            disp.setCurrent(f);
            vc.setVisible(true);
            
            try {
                player.start();
            }catch (Exception e3){
                error=true;
                errormsg+=e3.getMessage();
                return;
            }
            
            
        }
        private void ohSnap(){
            
            try {
                vc.setVisible(false);
                String enc="encoding=jpeg&width=1024&height=768";
                byte [] imgBytes = vc.getSnapshot(enc);
                img = Image.createImage(imgBytes, 0, imgBytes.length);
            }catch (Exception e){
                error=true;
                errormsg+=e.getMessage();
            }
            
        }
        private void showSnap(){
            
            PicCanvas pc=new PicCanvas(img);
            pc.addCommand(cmdExit);
            pc.setCommandListener(this);
            disp.setCurrent(pc);
            
        }
        private class PicCanvas extends Canvas{
            
            private Image image;
            private int xmod=0,ymod=0;
            public PicCanvas(Image img){
                image=img;
                
            }
            public void paint(Graphics g){
                g.setColor(0x00FFffFF);
                g.fillRect(0,0,getWidth(),getHeight());
                if (image!=null){
                    g.drawImage(image,xmod,ymod,0);
                }
                
            }
            
            public void keyPressed(int keyCode) {
                int action=getGameAction(keyCode);
               
                if (action==RIGHT){
                    xmod-=50;
                }else if (action==LEFT){
                    xmod+=50;
                }else if (action==UP){
                    ymod+=50;
                }else if (action==DOWN){
                    ymod-=50;
                }
                
                repaint();
                
            }
            
        }
    }

  14. #14
    Registered User
    Join Date
    May 2007
    Posts
    13

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi,

    1stly thanks for going to all this trouble, your sample code is greatly appreciated.

    I was able to build your sample and run it ok.

    However for -

    String enc="encoding=jpeg&width=1024&height=768";

    I still get the same old error ( popping up in its own dialogue ) saying -

    Unhandled exception. Close application ? Yes No

    If I change back to -

    String enc="encoding=jpeg&width=960&height=720";

    it runs ok on the N95 as expected, with image displayed and scrolling working etc.

    Going back to -

    String enc="encoding=jpeg&width=1024&height=768";

    I found that the byte array is being created ok by -

    byte [] imgBytes = vc.getSnapshot(enc);

    as I can write it out to the filesystem ok & then read the resulting jpeg file ok on my PC.

    I also found that the error mentioned is being generated in the call to -

    img = Image.createImage(imgBytes, 0, imgBytes.length);

    If I trap all possible (documented) exceptions for Image.createImage ( including ArrayIndexOutOfBoundsException, NullPointerException, IllegalArgumentException and Exception ) I am still unable to intercept the 'Unhandled exception' error (!)

    This code was redundant anyway as the exceptions were already being trapped & caught in your code.

    So I guess your suggestion about their being different n95 models may be true. ( Mine was source out of Asia-Singapore, I live in Australia and procured it via Ebay through an Australian seller ) The phone seems fairly recent with the original rom being V10.0.18 from March 2007. I had updated the rom to V11.0.026 2007-04-17 subsequently.

    I also tried -

    String enc="encoding=jpeg&width=1280&height=960";

    to see if I could capture and write this image size to the file system but in this case (or greater resolutions) I get a Symbain OS Error: -4.
    This error occurs before the java security user request to allow the application to access the camera-snapShot.

    So I guess that, in my case -

    String enc="encoding=jpeg&width=1024&height=768";

    is pretty much the limit of what is supported (currently?) for java on the N95.

    Are you able to capture anything like -

    String enc="encoding=jpeg&width=1280&height=960";

    or higher ?

    In any case I still need to create an Image object from the returned byte array in my intended application for subsequent processing, so 960x720 will have to do. Unless of course higher resolutions might be supported for java in a subsequent rom release...

    Again, many thanks for your interest and responses in helping me with this.

    Regards

  15. #15
    Registered User
    Join Date
    Mar 2007
    Posts
    53

    Re: jsr234 camera getSnapShot() on Nokia N95

    Hi, unfortunately I dont have N95 with me at the moment so I cant test that 1280x960 with it, however: I did try and succeed taking 1280x960 with N76 and 5500. And Ive taken 1024*768 with N73. I really cant understand how you can take only 960x720 with your N95. All phones Ive used have been bought from Finland though so I guess there is some regional differencies though it doesnt make sense. As a last resort, have you tried checking if settings in phones own camera app have any effect? They shouldnt have but if there is some parameter set there that the camera hardware always checks then it might be worth a try to see if they have any effect. Perhaps some nokia forum expert might shed a little light to our dilemma here?

Similar Threads

  1. Infra-red capability
    By Symbian_Challenge_0412 in forum General Development Questions
    Replies: 1
    Last Post: 2005-08-16, 18:24
  2. Nokia Mobile VPN Client
    By marcyl in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2003-12-01, 14:47

Posting Permissions

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