正在做一个j2me的项目,需要用相机拍照然后上传服务器

java_father 2010-09-20 10:11:23
有朋友做过这样的项目吗?

我基于SUN的WTK 在模拟器上实现了拍照功能

但是真机测试时候 打开--拍照 却灰屏。

打不开手机的摄像。
...全文
95 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
suhu407563045 2010-09-28
要你的手机 支持 视频捕获
不是有摄像头就可以
supports.video.capture 是否支持视频捕获,如true
回复
huang_63188 2010-09-27
我学生。。。
回复
QQ153984069 2010-09-26
package prj13_1;

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import prj13_1.canvas.VideoCanvas;

public class VideoControlExample extends MIDlet implements CommandListener{
private Display display;
private Form form;
private Command exit, back, capture, camera;
private Player player;
private VideoControl videoControl;
private Video video;

public VideoControlExample() {
display = Display.getDisplay(this);
form = new Form("Capture Video");
exit = new Command("Exit", Command.EXIT, 0);
camera = new Command("Camera", Command.SCREEN, 1);
back = new Command("Back", Command.BACK, 2);
capture = new Command("Capture", Command.SCREEN, 3);
form.addCommand(camera);
form.setCommandListener(this);
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
notifyDestroyed();

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
display.setCurrent(form);

}

public void commandAction(Command c, Displayable s){
String label = c.getLabel();
if (label.equals("Exit")){
try {
this.destroyApp(true);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (label.equals("Camera")) {
showCamera();
} else if (label.equals("Back"))
display.setCurrent(form);
else if (label.equals("Capture")) {
video = new Video(this);
video.start();
}
}

public void showCamera(){
try{
player = Manager.createPlayer("capture://video");
player.realize();
videoControl = (VideoControl)player.getControl("VideoControl");
Canvas canvas = new VideoCanvas(this, videoControl);
canvas.addCommand(back);
canvas.addCommand(capture);
canvas.setCommandListener(this);
display.setCurrent(canvas);
player.start();
} catch (IOException ioe) {} catch (MediaException me) {}
}

class Video extends Thread {
VideoControlExample midlet;
public Video(VideoControlExample midlet) {
this.midlet = midlet;
}

public void run() {
captureVideo();
}

public void captureVideo() {
try {
byte[] photo = videoControl.getSnapshot(null);
Image image = Image.createImage(photo, 0, photo.length);
form.append(image);
display.setCurrent(form);
player.close();
player = null;
videoControl = null;
} catch (MediaException me) { }
}
};
}
回复
QQ153984069 2010-09-26
没有碰到过。应该是代码问题。
回复
napier 2010-09-26
你找找真机厂商提供的Java API看看吧,会不会是手机不支持通用API
回复
zyc1314199 2010-09-25
看看代码。。。。。
回复
相关推荐
发帖
J2ME
创建于2007-09-28

1.3w+

社区成员

Java J2ME
申请成为版主
帖子事件
创建了帖子
2010-09-20 10:11
社区公告
暂无公告