Does this work?
PHP Code:
import java.io.IOException;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;
public class Snapper extends MIDlet implements CommandListener {
private static final Command EXIT = new Command("Exit", Command.EXIT, 0);
private static final Command SNAP = new Command("Snap", Command.OK, 0);
private Displayable shown;
public void startApp() {
if (shown == null) {
shown = new ViewFinder();
shown.addCommand(SNAP);
try {
((ViewFinder) shown).initialize();
} catch (Exception e) {
Form f = new Form("Error");
f.append(e.toString());
shown = f;
}
shown.addCommand(EXIT);
shown.setCommandListener(this);
}
setCurrent(shown);
}
public void pauseApp() {
// do nothing
}
public void destroyApp(boolean must) {
// do nothing
}
private void setCurrent(Displayable d) {
shown = d;
Display.getDisplay(this).setCurrent(d);
}
public void commandAction(Command c, Displayable d) {
if (c == EXIT) {
notifyDestroyed();
} else if (c == SNAP) {
Form f;
try {
byte[] image = ((ViewFinder) d).snap();
f = new Form("Success");
f.append(Image.createImage(image, 0, image.length));
} catch (Exception e) {
f = new Form("Error");
f.append(e.toString());
}
f.addCommand(EXIT);
f.setCommandListener(this);
setCurrent(f);
}
}
private static class ViewFinder extends Canvas {
private Player player;
private VideoControl video;
public void initialize() throws MediaException, IOException {
player = Manager.createPlayer("capture://image");
player.start();
video = (VideoControl) player.getControl("VideoControl");
video.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
video.setDisplayLocation(2, 2);
video.setDisplaySize(getWidth() - 4, getHeight() - 4);
video.setVisible(true);
}
public byte[] snap() throws MediaException {
byte[] data = video.getSnapshot(null);
player.stop();
return data;
}
protected void paint(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
}