2012-03-08 167 views
1

我想從捕捉video一個LWUITImage。問題是,MediaException提高調用getSnapshot()時:在「CameraCanvas」視頻捕捉問題

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; 
    } 

代碼:

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

那麼,什麼可能是問題的原因是什麼?

+0

我不知道很多關於帆布/ LCDUI。 ¿您可以使用LWUIT UI元素嗎? – frayab 2012-03-08 08:55:31

+0

將它轉換爲LWUIT將是一件困難的工作! – pheromix 2012-03-08 09:19:23

+0

我有像你這樣的問題,看看如何在LWUIT捕捉圖像這個例子中,我希望這可以幫助您http://stackoverflow.com/questions/7742397/how-to-capture-images-using-lwuit-videocomponent/7796680#7796680 – frayab 2012-03-08 09:28:03

回答

1

MMAPI具有創建的圖像的能力,並且可以很容易地把它轉化爲一個LWUIT圖像(其具有創建接受一個對象圖像)。但是,出於某種原因,提出此API的「天才」會將圖像捕獲爲受限制的API以保護您的隱私。因此,如果沒有操作員/製造商簽名,就無法調用此API。