当用户用手机拍照时,我希望LWUIT获得一张特定的照片,并将其添加到记录库中,然后检索该照片。如何做到这一点呢?
发布于 2011-06-16 16:51:19
好的,我通过一个命令让应用程序启动摄像头:
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);
mPlayer.start();在mCaptureCommand命令的actionPerformed中:
public void capture() {
try {
// Get the image.
byte[] raw = mVideoControl.getSnapshot(null);
// "encoding=png&width=320&height=240");
bytelen = raw.length;
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);
}
}createThumbnail的代码如下:
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;
}现在,我不知道在调用createThumbnail方法时,即在调用Image.createImage之后,图像存储在哪里:有两个createImage调用,一个在capture()方法中,另一个在createThumbnail()方法中。但我真正的问题是要知道创建的图像的位置,以及如何将其与银行客户的recordStore id相关联。
发布于 2011-06-15 17:33:03
RMS不适合存储照片,因为RMS是为小容量存储而设计的。你不能处理huge数量的数据。更好的是你可以从手机内存或存储卡中读取。另外,如何在没有应用程序的情况下拍摄当前捕获的照片?
编辑:
您可以为taking the photo开发应用程序并将其存储在RMS(但不是大量)中,也可以通过调用web service将其存储在服务器中。
https://stackoverflow.com/questions/6353977
复制相似问题