j2me 手机图片上传(2)

package com.box.ui;
import javax.microedition.lcdui.*;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;

import com.box.MIDlet.MainWindow;


public class UpUI extends  Canvas  implements CommandListener {
    private Display display;
    private MainWindow m;

    private  Command backCommand = new Command(boxtext.back,Command.BACK,1);
    private Command okCommand = new Command(boxtext.ok,Command.OK,1);
    private Alert alert = null;
    private boolean error = false; 
    public VideoControl videoControl = null;
    public Player capturePlayer = null;
    private byte[] data = null;
    private Image image = null;
    public UpUI(MainWindow p,Display d) {
      
        m = p;
        display = d;
       
        //Player capturePlayer = null;
     
        this.addCommand(backCommand);
        this.addCommand(okCommand);
        this.setCommandListener(this);
        try {
            capturePlayer = Manager.createPlayer("capture://video");     
            capturePlayer.realize();
           
            // now create the canvas
          
          
          } catch(Exception e) {
            error(e);
          }
          try {
              capturePlayer.start();
            } catch(Exception e) { error(e); }   
            videoControl =
                (VideoControl)capturePlayer.getControl(
                  "javax.microedition.media.control.VideoControl");
             
              // if not present, throw error
            
              // init display mode to use direct video and this canvas
              videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
             
             try { // try and set to full screen
                videoControl.setDisplayFullScreen(true);
              } catch(MediaException me) {
               
                // but some devices may not support full screen mode
                videoControl.setDisplayLocation(5, 5);
                try {
                  videoControl.setDisplaySize(getWidth() - 10, getHeight() - 10);
                } catch(Exception e) {}
               
             
              }
             
              // and make the video control visible
              videoControl.setVisible(true);
              videoControl.setDisplayLocation(5, 18);
            }
   
    void error(Exception e) {
        alert.setString(e.getMessage());
        alert.setTitle("Error");
        display.setCurrent(alert);
        e.printStackTrace();
        error = true;
      }  
  
    public void commandAction(Command cmd,Displayable displayable){
     if(cmd == backCommand){
      try {
    capturePlayer.stop();
    
   } catch (MediaException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   videoControl = null;
   capturePlayer.close();
      AppCanvas app = new AppCanvas(display,m);
      display.setCurrent(app);
     }
       
     
     if(cmd == okCommand){
      try {
       capturePlayer.stop();
       data = videoControl.getSnapshot(null);
       videoControl = null;
       capturePlayer.close();
   } catch (MediaException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
      sendPhoto send = new sendPhoto(m,display,data);
   display.setCurrent(send);
//   HttpThread thread = new HttpThread();
//   thread.setData(videoControl);
//         thread.start();
   
     }
    }
//    public void keyPressed(int keyCode) {
//      try {
//             capturePlayer.stop();
//            
//           } catch(Exception e) { error(e); }
     HttpThread thread = new HttpThread();
        thread.setData(videoControl);
        thread.start();
//
//    }

 protected void paint(Graphics g) {
  // TODO Auto-generated method stub
  g.setColor(0xffffff);
  g.fillRect(0, 0, getWidth(), getHeight());
   
    // and draw a rectangle with a different color
  g.setColor(0x44ff66);
  g.drawRect(0, 0,  getWidth() - 10, getHeight() - 10);
 }
   
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值