1
我想從捕捉video
一個LWUIT
Image
。問題是,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 ");
}
}
}
那麼,什麼可能是問題的原因是什麼?
我不知道很多關於帆布/ LCDUI。 ¿您可以使用LWUIT UI元素嗎? – frayab 2012-03-08 08:55:31
將它轉換爲LWUIT將是一件困難的工作! – pheromix 2012-03-08 09:19:23
我有像你這樣的問題,看看如何在LWUIT捕捉圖像這個例子中,我希望這可以幫助您http://stackoverflow.com/questions/7742397/how-to-capture-images-using-lwuit-videocomponent/7796680#7796680 – frayab 2012-03-08 09:28:03