⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cameraform.java

📁 基于Eclipse开发环境的J2ME motorola智能手机(E6)摄像头控制程序
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.IOException;
/**
/*
 * cameraForm.java
 *
 * Created on 2007年6月24日, 下午10:49
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author zhy
 */
public class cameraForm  extends Form implements CommandListener,Runnable
{
   Player p;
  VideoControl vc;

  int mintMode = VideoControl.USE_GUI_PRIMITIVE;

  Command cmdSnapshot = new Command("拍照",Command.OK,0);
  Command cmdBack = new Command("返回",Command.BACK,0);

  boolean mblnSnapshot = false;

  String mstrImageType = null;

  Camera midlet = null;
    /** Creates a new instance of cameraForm */
    public cameraForm(Camera m) 
    {
        super("camera");
	midlet = m;
    try
    {
      p = Manager.createPlayer("capture://video");
      p.realize();
      vc = (VideoControl) p.getControl("VideoControl");
      if (vc != null) 
      {
        Item item = (Item)vc.initDisplayMode(mintMode, null);
		append(item);
      }
      p.start();
    }
    catch(Exception e)
    {
      System.out.println("init Error:"+e.toString());
    }
        
        try 
        { 
            vc.setDisplayFullScreen(true);
 //           vc.setDisplaySize(240,60);
        }
       catch (MediaException me2) {}
              
     vc.setVisible(true);   

    try {
      append("图像格式为:"+System.getProperty("video.snapshot.encodings"));
      append("getContentType:" + p.getContentType());
      append("getDisplayWidth:" + vc.getDisplayWidth());
      append("getDisplayHeight:" + vc.getDisplayHeight());
      append("getDisplayX:" + vc.getDisplayX());
      append("getDisplayY:" + vc.getDisplayY());
      append("getSourceWidth:" + vc.getSourceWidth());
      append("getSourceHeight:" + vc.getSourceHeight());      
    }
    catch (Exception e) {}
    
    addCommand(cmdSnapshot);
    addCommand(cmdBack);
    setCommandListener(this);
   (new Thread(this)).start();
    }
    
    public void commandAction(Command cmd,Displayable dis){
    try{
		if(cmd.equals(cmdSnapshot)){
			mblnSnapshot = true;	
		}else if(cmd.equals(cmdBack)){
			midlet.display.setCurrent(midlet.lstMenu);
			vc = null;
			p.close();
			p = null;
		}
    }catch(Exception e){
      this.append(e.toString());
    }
  }

     public void run(){
	while(true)
        {
		try
                {
			Thread.sleep(100);
		}catch(Exception e){}
                
                int argb[];
		if(mblnSnapshot)
                {
			mblnSnapshot = false;
			try{
				byte[] RGB = vc.getSnapshot("encoding=jpeg&width=320&height=240");
				if(get(0).getClass().getName().equals("javax.microedition.lcdui.ImageItem"))
                                {
					delete(0);
				}
				Image image = Image.createImage(RGB,0,RGB.length);
                                argb = new int[image.getWidth()*image.getHeight()];
                                image.getRGB(argb,0,image.getWidth(),0,0,image.getWidth(),image.getHeight());//获得图片的ARGB值
              			ImageItem item = new ImageItem("图片大小为:"+RGB.length+"字节"+
                               "颜色:"+argb.length+"图像格式为:"+System.getProperty("video.snapshot.encodings")+
                               "宽为:"+image.getWidth()+"高为"+image.getHeight(),image,ImageItem.LAYOUT_DEFAULT,"");
			        insert(0,item);
			}catch(Exception e)
                        {
				System.out.println(""+e.toString());
			}
		}
	}
  }

   
    
}

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -