Nokia E71摄像头程序无法安装jar

haoweishow01 2010-11-10 10:51:44
下面的代码是从sun的官网上下载的。我在NetBeans6.8上建立项目,拷贝这两个文件,然后直接部署到手机上,安装的时候报无效的Jar.
各位大侠知道是什么原因吗?
或者告诉小弟,怎么才能在s60 v3版本里控制摄像头呢?

谢谢啦,另外帖子内容太长,删除了一些License的注释内容。

SnapperMIDlet.java

/* License
*
* Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved.
* nuclear facility.
*/

import java.io.IOException;

import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;

public class SnapperMIDlet
extends MIDlet
implements CommandListener {

private Display mDisplay;
private Form mMainForm;
private Command mExitCommand, mCameraCommand;
private Command mBackCommand, mCaptureCommand;
private Player mPlayer;
private VideoControl mVideoControl;

public SnapperMIDlet() {
mExitCommand = new Command("Exit", Command.EXIT, 0);
mCameraCommand = new Command("Camera", Command.SCREEN, 0);
mBackCommand = new Command("Back", Command.BACK, 0);
mCaptureCommand = new Command("Capture", Command.SCREEN, 0);

mMainForm = new Form("Snapper");
mMainForm.addCommand(mExitCommand);
String supports = System.getProperty("video.snapshot.encodings");
if (supports != null && supports.length() > 0) {
mMainForm.append("Ready to take pictures.");
mMainForm.addCommand(mCameraCommand);
} else {
mMainForm.append("Snapper cannot use this "
+ "device to take pictures.");
}
mMainForm.setCommandListener(this);
}

public void startApp() {
mDisplay = Display.getDisplay(this);

mDisplay.setCurrent(mMainForm);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) {
destroyApp(true);
notifyDestroyed();
} else if (c == mCameraCommand) {
showCamera();
} else if (c == mBackCommand) {
mDisplay.setCurrent(mMainForm);
} else if (c == mCaptureCommand) {
capture();
}
}

private void showCamera() {
try {
mPlayer = Manager.createPlayer("capture://video");
mPlayer.realize();

mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");
Canvas canvas = new CameraCanvas(this, mVideoControl);
canvas.addCommand(mBackCommand);
canvas.addCommand(mCaptureCommand);
canvas.setCommandListener(this);
mDisplay.setCurrent(canvas);

/*
Form form = new Form("Camera form");
Item item = (Item)mVideoControl.initDisplayMode(
GUIControl.USE_GUI_PRIMITIVE, null);
form.append(item);
form.addCommand(mBackCommand);
form.addCommand(mCaptureCommand);
form.setCommandListener(this);
mDisplay.setCurrent(form);
*/

mPlayer.start();
} catch (IOException ioe) {
handleException(ioe);
} catch (MediaException me) {
handleException(me);
}
}

public void capture() {
try {
// Get the image.
byte[] raw = mVideoControl.getSnapshot(null);
Image image = Image.createImage(raw, 0, raw.length);

Image thumb = createThumbnail(image);

// Place it in the main form.
if (mMainForm.size() > 0 && mMainForm.get(0) instanceof StringItem) {
mMainForm.delete(0);
}
mMainForm.append(thumb);

// Flip back to the main form.
mDisplay.setCurrent(mMainForm);

// Shut down the player.
mPlayer.close();
mPlayer = null;
mVideoControl = null;
} catch (MediaException me) {
handleException(me);
}
}

private void handleException(Exception e) {
Alert a = new Alert("Exception", e.toString(), null, null);
a.setTimeout(Alert.FOREVER);
mDisplay.setCurrent(a, mMainForm);
}

private Image createThumbnail(Image image) {
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();

int thumbWidth = 64;
int thumbHeight = -1;

if (thumbHeight == -1) {
thumbHeight = thumbWidth * sourceHeight / sourceWidth;
}

Image thumb = Image.createImage(thumbWidth, thumbHeight);
Graphics g = thumb.getGraphics();

for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
g.setClip(x, y, 1, 1);
int dx = x * sourceWidth / thumbWidth;
int dy = y * sourceHeight / thumbHeight;
g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
}
}

Image immutableThumb = Image.createImage(thumb);

return immutableThumb;
}
}


CameraCanvas.java

/* License
*
, construction, operation or maintenance of any
* nuclear facility.
*/

import javax.microedition.lcdui.*;
import javax.microedition.media.MediaException;
import javax.microedition.media.control.VideoControl;

public class CameraCanvas
extends Canvas {

private SnapperMIDlet mSnapperMIDlet;

public CameraCanvas(SnapperMIDlet midlet, VideoControl videoControl) {
int width = getWidth();
int height = getHeight();

mSnapperMIDlet = midlet;

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

public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();

// Draw a green border around the VideoControl.
g.setColor(0x00ff00);
g.drawRect(0, 0, width - 1, height - 1);
g.drawRect(1, 1, width - 3, height - 3);
}

public void keyPressed(int keyCode) {
int action = getGameAction(keyCode);
if (action == FIRE) {
mSnapperMIDlet.capture();
}
}
}
...全文
153 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fishcat007 2010-11-11
  • 打赏
  • 举报
回复
不错~~ 谢谢

fishcat007 2010-11-11
  • 打赏
  • 举报
回复
不错~~ 谢谢

haoweishow01 2010-11-10
  • 打赏
  • 举报
回复
试了一下,真的是这个问题啊。加上那个就好了。

奇怪的是,我有另外个project,代码是自己写的,这个的jad里就有MIDlet-1: ****这些东西。

而这个工程我重新清理了再生成,还是没有。请问一下,这个可能是什么原因导致的呢?
谢谢你啦。
houjin_cn 2010-11-10
  • 打赏
  • 举报
回复
另外, 不知道E71的参数, 你代码中如果没有用到特殊的API

MicroEdition-Configuration: CLDC-1.0
MicroEdition-Profile: MIDP-2.0
houjin_cn 2010-11-10
  • 打赏
  • 举报
回复
少了一项下面这样的:
MIDlet-1: SnapperMIDlet, /icon.png, com.xxx.Main

com.xxx.Main改为你的Midlet类名
haoweishow01 2010-11-10
  • 打赏
  • 举报
回复
MIDlet-Jar-Size: 4350
MIDlet-Jar-URL: SnapperMIDlet.jar
MIDlet-Name: SnapperMIDlet
MIDlet-Vendor: Vendor
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.1
MicroEdition-Profile: MIDP-2.1


帮忙看看。谢谢啊
houjin_cn 2010-11-10
  • 打赏
  • 举报
回复
把你的JAD文件内容贴出来看看

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧