0

When the user takes photos with his phone I want LWUIT to get a specific photo to add to a recordstore and later retrieve that photo. How to achieve that ?

bharath
  • 14,283
  • 16
  • 57
  • 95
  • Are you going to take the photo through your application? – bharath Jun 15 '11 at 07:14
  • @bhakki: No , the photo is taken manually by the user. –  Jun 15 '11 at 08:27
  • Then why you are storing into RMS? just taking from phone memory or memory card. – bharath Jun 15 '11 at 08:53
  • @bhakki: But how to make the relationship between a photo and a recordstore id ? For example there is a recordstore of a banking client , and the credit-agent will take a photo of this client's car to be a proof of mortgage. So how to make the relationship ? –  Jun 15 '11 at 09:15

2 Answers2

1

RMS is not good for storing the Photo's. Because RMS designed for small amount of storage. You can't handle huge amount of data. Better you can read from phone memory or memory card. Also how you can take the currently captured photo without your application?

Edit:

You can develop the application for taking the photo and store it in RMS(But not huge amount) or store it in server through calling web service.

Community
  • 1
  • 1
bharath
  • 14,283
  • 16
  • 57
  • 95
1

Ok , I make the application starts the camera through a command :

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

In the actionPerformed of the mCaptureCommand command :

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

The code of 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;
    }

Now I do not know where the Image is stored when calling the createThumbnail method , that is after calling Image.createImage : there are two createImage calls one in the capture() method and one in the createThumbnail() method. But my real problem is to know the location of the created image and how to associate it with a banking-client recordStore id.

  • How to give a filename to an Image ? For example in my above code : Image immutableThumb = Image.createImage(thumb); How to assign a name to this Image , or does this Image get a system-generated name when created ? If so how to get this ? This is because I want to use JSR 75 ( FileConnection ) to create the physical file associated with the Image. Although when working with JSR 75 ( Connector.open() ) we must supply a name for the file to manipulate. So how to get the name of the Image ? –  Jun 16 '11 at 12:48