1

I want to create a LWUIT Image from the captured video. The problem is that the MediaException is raised when calling getSnapshot() :

private void showCamera() // called when clicking the "open camera" command
    {
        try
        {
            Player mPlayer;
            VideoControl mVideoControl;
            mPlayer = Manager.createPlayer("capture://video");
            mPlayer.realize();
            mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");
            Canvas canvas = new CameraCanvas(this, mVideoControl, mPlayer, getFirstAvailableRoot(), "ADC"+adcId); // adcId is "1"
            isFromPositionnement = true; // static variable
            javax.microedition.lcdui.Display.getDisplay(controler).setCurrent(canvas);
            mPlayer.start();
        } catch (IOException ex) {
            handleException();
        } catch (MediaException ex) {
            handleException();
        }
    }

private String getFirstAvailableRoot()
    {
        short iter;
        String root = "Phone:/";
        iter = 0;
        Enumeration drives = FileSystemRegistry.listRoots();
        while(drives.hasMoreElements() && iter < 1) {
            root = String.valueOf(drives.nextElement());
            iter++;
        }
        return root;
    }

Code in "CameraCanvas" :

    public class CameraCanvas extends Canvas implements CommandListener 
    {
        ...
        public CameraCanvas(Ecran form, VideoControl videoControl, Player pPlayer, String pRoot, String dossierPhoto)
        {
            ...
            mCaptureCommand = new Command("Capturer", Command.SCREEN, 1);
            addCommand(mCaptureCommand);
            setCommandListener(this);
            ...
            videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
            try
            {
                videoControl.setDisplayLocation(2, 2);
                videoControl.setDisplaySize(width - 4, height - 4);
            } 
            catch (MediaException me)
            {
                try
                {
                    videoControl.setDisplayFullScreen(true);
                } 
                catch (MediaException me2)
                {}
            }
            videoControl.setVisible(true);
        }
        private void capture() // called when clicking the mCaptureCommand command
        {
            try
            {
                isPhotoCaptured = true;
                rawImg = vidCtrl.getSnapshot(null); // this throws the exception
                vidCtrl.setVisible(false);
                vidCtrl = null;
                mPlayer.close();
                mPlayer = null;
                repaint();
            }
            catch (MediaException me)
            {
                isPhotoCaptured = false;
                rawImg = null;
                vidCtrl.setVisible(false);
                vidCtrl = null;
                mPlayer.close();
                mPlayer = null;
                handleException("capture ");
            }
        }
    }

So what may be the cause of the issue ?

bharath
  • 14,283
  • 16
  • 57
  • 95
pheromix
  • 18,213
  • 29
  • 88
  • 158
  • I don't know much about Canvas/LCDUI. ¿Can you use LWUIT UI elements? – frayab Mar 08 '12 at 08:55
  • It will be a hard job to convert it to LWUIT ! – pheromix Mar 08 '12 at 09:19
  • I had a problem like yours, look at this example of how to capture image in LWUIT, i hope this help you http://stackoverflow.com/questions/7742397/how-to-capture-images-using-lwuit-videocomponent/7796680#7796680 – frayab Mar 08 '12 at 09:28
  • I noticed that even with fileConnection.create() for creating a file doesn't work ! there is something strange with my phone ! – pheromix Mar 08 '12 at 12:33
  • Finally I found the reason : there are a lot of recordstores in my app so there is no enough room for Images. – pheromix Apr 18 '12 at 12:43

1 Answers1

1

MMAPI has the ability to create an image and you can easily turn it to a LWUIT image (which has a create image that accepts an object). However, for some reason the "geniuses" who came up with this API made image capture a restricted API to protect your privacy. So effectively you can't invoke this API without an operator/manufacturer signature.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65