RecordStore和从手机拍摄的照片

时间:2011-06-15 06:39:12

标签: java-me photo lwuit rms recordstore

当用户使用手机拍照时,我希望LWUIT能够将特定照片添加到记录库中,然后再检索该照片。如何实现?

2 个答案:

答案 0 :(得分:1)

RMS不适合存储照片。因为RMS专为少量存储而设计。您无法处理huge数据量。您可以从手机记忆库或记忆卡中读取更好的内容。如何在没有应用程序的情况下拍摄当前拍摄的照片?

修改

您可以为taking the photo开发应用程序并将其存储在RMS中(但数量不大)或通过调用web service将其存储在服务器中。

答案 1 :(得分:1)

好的,我让应用程序通过命令启动摄像机:

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

在mPaptureCommand命令的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的位置,即在调用Image.createImage之后:在capture()方法中有两个createImage调用,createThumbnail()方法中有一个调用。但我真正的问题是要知道创建的图像的位置以及如何将其与银行客户端recordStore id相关联。