2012-05-09 9 views
1

私はこのアプリケーションを使用してJ2MEでアプリケーションを作成しています。画像をキャプチャすると同時にその画像をWebにアップロードできますサーバーが、私は私のNokia Cシリーズでこのアプリケーションを使用するときはいつでも私は画像をキャプチャすることができませんし、画像をキャプチャすることができますコンピュータを介してこのアプリケーションを使用するたびにコマンドが動作していない問題を見てください。私はこのアプリが役に立つと私のために有用なものとするために何をする必要があるかガイド............... .ThanksアミットここShowCamera方法でNokia Cシリーズ経由で画像をキャプチャしてWebサーバに送信することはできません

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



} 
+0

を使用してみてください – user1369219

+0

私はsam eproblemを持っています...解決策を持っていることができます私はノキアs40(ノキアc1)の問題を抱えています –

答えて

0

、代わりの

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

それがOEMをサポートしていますかどのように任意のNokiaデバイスの確認方法を教えも非常に緊急かつだ???? ....誰かが同じのために返信してください

Manager.createPlayer("capture://image"); 
関連する問題