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

📄 jsr184cammidlet.java

📁 Use mobile take picture
💻 JAVA
字号:
import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.media.MediaException;import javax.microedition.m3g.*;import javax.microedition.io.*;import javax.microedition.media.*;import javax.microedition.media.control.*;import java.io.IOException;import javax.microedition.media.*;import javax.microedition.media.control.*;import javax.microedition.midlet.MIDlet;public class JSR184CamMidlet extends MIDlet implements CommandListener {    private TextureCreator tc;    private Command ExitCommand;    private Display Display;    private Image texImage = null;        public void startApp() {        Display = Display.getDisplay(this);        ExitCommand = new Command("Exit", Command.EXIT, 0);        tc = new TextureCreator();        tc.addCommand(ExitCommand);        tc.setCommandListener(this);        Display.setCurrent(tc);    }    public void pauseApp() {    }    public void destroyApp(boolean unconditional) {    }     public void commandAction(Command command, Displayable displayable) {        if(command.getCommandType() == Command.EXIT){            notifyDestroyed();        }else if(command.getCommandType() == Command.OK){  // display 3D-canvas            texImage = tc.getTexture();        }else if(command == tc.CaptureCommand){ // capture image            tc.snapShot();        }    }} class TextureCreator extends Canvas{    private Image mTextureImage = null;    protected Command CaptureCommand,CameraCommand,ExitCommand,BackCommand;    private Command DoneCommand ;    private VideoControl vc; // The videocontrol and the player is used to capture the image.    private Player player;    private Form MainForm;        public TextureCreator(){        CaptureCommand = new Command("Capture", Command.SCREEN, 0);        DoneCommand = new Command("Done", Command.OK, 0);         addCommand(CaptureCommand);        addCommand(DoneCommand);         try{            player = Manager.createPlayer("capture://video");            player.realize();            vc = (VideoControl)player.getControl("VideoControl");            vc.initDisplayMode(vc.USE_DIRECT_VIDEO, this);            vc.setDisplaySize(256,256); // only display a 256x256 part of the image since we need the final image to be the power of tow            vc.setDisplayLocation(0, getHeight()-256);            player.start();         }catch(Exception e){            System.out.println(e.getMessage());            System.out.println(e);        }    }    private void stop(){        vc = null;        player.close();        player = null;    }     public Image getTexture(){        stop();        return mTextureImage;    }                public void paint(Graphics g) {        if(mTextureImage != null){            g.setColor(0xFFFFFF);            g.fillRect(0, 0, getWidth(), getHeight());            g.drawImage(mTextureImage, 0, 0, 0);        }    }    public Image snapShot(){        byte []raw;        try{            raw = vc.getSnapshot(null);            mTextureImage = Image.createImage(raw, 0, raw.length);        }catch(Exception e){            System.out.println(e.getMessage());            System.out.println(e);        }        // create a 256x256 image since the texture must be the power of two.        Image m = Image.createImage(256,256);        Graphics g = m.getGraphics();        g.drawImage(mTextureImage, 0, -mTextureImage.getHeight()+256, 0); // draw the part of the captured image we want to use as texture.        mTextureImage = null;        mTextureImage = Image.createImage(m); // We need an immutable image as texture.        repaint();        return mTextureImage;    }    public void playerUpdate(javax.microedition.media.Player player, String str, Object obj) {    }}

⌨️ 快捷键说明

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