1

J2MEでアプリケーションを作成しています。このアプリケーションを使用すると、ユーザーは画像をキャプチャすると同時にその画像をWebサーバーにアップロードできますが、NokiaCシリーズでこのアプリを使用するたびにできません。画像をキャプチャし、コンピュータを介してこのアプリケーションを使用すると、画像をキャプチャできるが送信コマンドが機能しない場合は、問題を確認してこの問題を解決し、このアプリを有用で役立つものにするために必要なことをガイドしてください……… ……。ありがとうAmitここに

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

int status = 0;
byte localData[];

public myMidlet() {
display = Display.getDisplay(this);
form = new Form("My Form");
    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);
    send = new Command("Send", Command.OK, 1);
    form.addCommand(camera);
    form.addCommand(exit);
    form.setCommandListener(this);
}

public void startApp() {
    display.setCurrent(form);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional){
    notifyDestroyed();
}

public void commandAction(Command c, Displayable s){
    String label = c.getLabel();
    if (label.equals("Exit")){
        destroyApp(true);
    } 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();

        form.addCommand(send);
        form.removeCommand(camera);
    }
    else if( label.equalsIgnoreCase("Send") ){
        try {
            startSendOperation();
        } catch (Exception ex) {
        }

    }

}
    public boolean uploadImage( String uri, byte[] rawImage)throws Exception
{

HttpConnection httpConnection;
OutputStream    out;

// Open connection to the script
httpConnection = (HttpConnection)Connector.open( uri );

// Setup the request as an HTTP POST and encode with form data
httpConnection.setRequestMethod( HttpConnection.POST );
httpConnection.setRequestProperty( "Content-type", "application/
x-www-form-urlencoded" );

// Encode the imagedata with Base64
String encoded = Base64.encode( rawImage ).toString();

// Build the output and encoded string
String    output    = "imgdata=" + encoded;

// Set the content length header
httpConnection.setRequestProperty("Content-Length", Integer.toString
((output.getBytes().length)));

// Open the output stream and publish data
out = httpConnection.openOutputStream();
out.write( output.getBytes() );

// Flush the buffer (might not be necessary?)
out.flush();

// Here you might want to read a response from the POST to make
// sure everything went OK.

// Close everything down
if( out != null )
if( httpConnection != null )
httpConnection.close();

// All good
return true;
}

public void startSendOperation() throws Exception{

    boolean res = uploadImage( "http://www.xxx.com/postFolder?", localData);

}



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 {
    myMidlet midlet;
    public Video(myMidlet midlet) {
        this.midlet = midlet;
    }

    public void run() {
        captureVideo();
    }


    public void captureVideo() {
        try {
            byte[] photo = videoControl.getSnapshot(null);
            localData = photo;
            Image image = Image.createImage(photo, 0, photo.length);

            form.append(image);
            display.setCurrent(form);
            player.close();
            player = null;
            videoControl = null;
        } catch (MediaException me) { }
    }
};
}

class VideoCanvas extends Canvas {
private myMidlet midlet;

public VideoCanvas(myMidlet midlet, VideoControl videoControl) {
    int width = getWidth();
    int height = getHeight();
    this.midlet = midlet;

    videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
    try {
        videoControl.setDisplayLocation(2, 2);
        videoControl.setDisplaySize(width - 4, height - 4);
    } catch (MediaException me) {}
    videoControl.setVisible(true);
}

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

    g.setColor(255, 0, 0);
    g.drawRect(0, 0, width - 1, height - 1);
    g.drawRect(1, 1, width - 3, height - 3);
}



}
4

1 に答える 1

0

ShowCamera メソッドでは、代わりに

Manager.createPlayer("capture://video");

使ってみて

Manager.createPlayer("capture://image");
于 2012-11-24T10:35:13.513 に答える