视频捕获问题

时间:2012-03-08 07:32:26

标签: java-me lwuit

我想从捕获的LWUIT创建Image video。问题是调用MediaException时会引发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;
    }

“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 ");
            }
        }
    }

那么问题的原因可能是什么?

1 个答案:

答案 0 :(得分:1)

MMAPI能够创建图像,您可以轻松将其转换为LWUIT图像(具有接受对象的创建图像)。然而,出于某种原因,提出此API的“天才”使图像捕获受限制的API以保护您的隐私。因此,如果没有运营商/制造商签名,您无法调用此API。