`
ming_fanglin
  • 浏览: 227176 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

J2ME测试小工具(camera)

阅读更多
import java.util.Vector;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.MIDlet;

public class CameraMID extends MIDlet implements CommandListener ...{

    private MyCanvas canvas;

    private Player myPlayer;
    private VideoControl videoControl = null;
//    private FocusControl focusControl = null;
//    private ZoomControl zoomControl = null;
//    private ExposureControl exposureControl = null;

    private Vector er = new Vector();

    private Form form;

    private Command cmdPlay;
    private Command cmdError;
    private Command cmdQuit;

    public static CameraMID mid;

    public byte[] data;
    public Image img;

    public CameraMID() ...{
        form = new Form("test");
        cmdPlay = new Command("play", Command.OK, 0);
        cmdError = new Command("show error", Command.ITEM, 1);
        cmdQuit = new Command("quit", Command.EXIT, 2);
        form.addCommand(cmdPlay);
        form.addCommand(cmdError);
        form.addCommand(cmdQuit);
        form.setCommandListener(this);
        Display.getDisplay(this).setCurrent(form);

        canvas = new MyCanvas();
        mid = this;
       
        try ...{
            String str = System.getProperty("video.snapshot.encodings");
            if (null == str) ...{
                str = "SSN";
            } else ...{
                str = "SSY";
            }
            er.addElement(str);
        } catch (Exception e) ...{
            er.addElement(e.toString());
        }
    }

    public void commandAction(Command c, Displayable d) ...{
        if (c.equals(cmdPlay)) ...{
            Display.getDisplay(this).setCurrent(canvas);
            initPlayer();
        } else if (c.equals(cmdError)) ...{
            form.deleteAll();
            for (int i = 0; i < er.size(); i++) ...{
                form.append((String) er.elementAt(i));
            }
        } else if (c.equals(cmdQuit)) ...{
            notifyDestroyed();
        }
    }

    private void initPlayer() ...{
        new Thread() ...{
            public void run() ...{
                freePlayer();
                try ...{
                    myPlayer = Manager.createPlayer("capture://video");
                    myPlayer.realize();
                    videoControl = (VideoControl) myPlayer
                            .getControl("VideoControl");
                    videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,
                            canvas);
                    myPlayer.start();
                    videoControl.setVisible(true);
                    videoControl.setDisplayLocation(20, 18);
                    videoControl.setDisplaySize(200, 230);
                } catch (Exception e) ...{
                    er.addElement(e.toString());
                }
//                try {
//                    focusControl = (FocusControl) myPlayer
//                            .getControl("FocusControl");
//                    if (focusControl.isMacroSupported()) {
//                        focusControl.setMacro(true);
//                    }
//                    if (focusControl.isAutoFocusSupported()) {
//                        autoFocusFlg = true;
//                    } else {
//                        autoFocusFlg = false;
//                    }
//                } catch (Exception e) {
//                    er.addElement("focus " + e.toString());
//                }
//
//                try {
//                    zoomControl = (ZoomControl) myPlayer
//                            .getControl("ZoomControl");
//
//                    zoomControl.setDigitalZoom(100);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                    zoomControl.setDigitalZoom(ZoomControl.NEXT);
//                } catch (Exception e) {
//                    er.addElement("zoom " + e.toString());
//                }
//
//                try {
//                    exposureControl = (ExposureControl) myPlayer
//                            .getControl("ExposureControl");
//                    exposureControl.setISO(0);
//                } catch (Exception e) {
//                    er.addElement("exposure " + e.toString());
//                }
            }
        }.start();
    }

    private void freePlayer() ...{
        try ...{
            myPlayer.stop();
            myPlayer.deallocate();
        } catch (Exception e) ...{
        }
        try ...{
            myPlayer.close();
        } catch (Exception e) ...{
        }
    }

    private void snapshot() ...{
        new Thread() ...{
            public void run() ...{
                try ...{
                    er.addElement("getSnapshot ");
                    data = videoControl.getSnapshot("encoding=jpeg&width=640&height=480");
                    er.addElement("getSnapshot end ");
                    img = Image.createImage(data, 0, data.length);
                    form.deleteAll();
                    form.append(img);
                    Display.getDisplay(mid).setCurrent(form);
                    er.addElement("end ");

                    String time = Long.toString(System.currentTimeMillis());
                    String path = "file:///C:/pictures/" + time + ".png";
                    DeviceWirteFile(data, path);
                } catch (Exception e) ...{
                    er.addElement("snapshot " + e.toString());
                }
            }
        }.start();
    }

    private void zoomIn() ...{
//        if (zoomControl != null) {
//            zoomControl.setDigitalZoom(ZoomControl.NEXT);
//        }
    }

    private void zoomOut() ...{
//        if (zoomControl != null) {
//            zoomControl.setDigitalZoom(ZoomControl.PREVIOUS);
//        }
    }

    public void autoFocus() ...{
        if (autoFocusFlg) ...{
//            try {
//                focusControl.setFocus(-1000);
//            } catch (Exception e) {
//                er.addElement("autofocus " + e.toString());
//            }
        }
    }

    private boolean autoFocusFlg = false;

    private class MyCanvas extends Canvas implements CommandListener ...{

        private Command cmdOK;
        private Command cmdBack;
        private Command cmdFocus;

        public MyCanvas() ...{
            cmdOK = new Command("snapshot", Command.OK, 0);
            cmdBack = new Command("back", Command.BACK, 1);
            cmdFocus = new Command("auto focus", Command.ITEM, 2);
            addCommand(cmdOK);
            addCommand(cmdBack);
            addCommand(cmdFocus);
            setCommandListener(this);
        }

        public void paint(Graphics g) ...{
        }

        public void commandAction(Command c, Displayable d) ...{
            if (c.equals(cmdOK)) ...{
                autoFocus();
                snapshot();
            } else if (c.equals(cmdBack)) ...{
                freePlayer();
                Display.getDisplay(mid).setCurrent(form);
            } else if (c.equals(cmdFocus)) ...{
                autoFocus();
            }
        }

        public void keyRepeated(int key) ...{
            int nk = getGameAction(key);
            switch (nk) ...{
            case UP:
            case LEFT:
                zoomIn();
                break;
            case DOWN:
            case RIGHT:
                zoomOut();
                break;
            }
        }

    }

    private void DeviceWirteFile(byte[] data, String fileName) throws Exception ...{
        // FileConnection conn = (FileConnection) Connector.open(fileName,
        // Connector.READ_WRITE);
        // if (conn.exists()) {
        // conn.delete();
        // conn.create();
        // } else {
        // conn.create();
        // }
        // OutputStream os = conn.openOutputStream();
        //
        // os.write(data);
        // os.flush();
        // os.close();
        // conn.close();
    }

    protected void destroyApp(boolean arg0) ...{
    }

    protected void pauseApp() ...{
    }

    protected void startApp() ...{
    }

}
分享到:
评论

相关推荐

    J2me音频测试工具

    在J2ME中处理音频是开发者经常遇到的任务,而“J2ME音频测试工具”就是为了帮助开发者更好地理解和调试音频功能而创建的。这个工具可能包含了各种功能,比如播放、暂停、停止音频,调整音量,以及对不同音频格式的...

    J2ME测试软件图片版(黑盒测试)

    总结来说,这个“J2ME测试软件图片版(黑盒测试)”是一个全面的测试工具,旨在帮助开发者和测试团队对J2ME应用程序进行有效测试,特别是关注图形界面、日期处理以及音频功能。其包含的源码提供了学习和定制的机会,...

    J2ME开发详解工具篇 pdf

    J2ME WTK的模拟器是开发者在真实设备可用之前测试应用的重要工具。它模拟了不同类型的J2ME支持设备,如手机或PDA的硬件和操作系统特性。开发者可以通过调整模拟器配置来测试应用程序在不同设备上的表现。 4. **...

    J2ME混淆打包工具proguard4.4.zip

    **J2ME混淆打包工具ProGuard 4.4详解** J2ME(Java 2 Micro Edition)是Java平台的一个子集,主要用于嵌入式设备和移动设备上的应用程序开发。在开发过程中,为了保护代码安全、防止反编译,开发者通常会使用混淆...

    J2ME工具篇.rar

    6. **BlackBerry JDE**:对于黑莓设备,BlackBerry Java Development Environment(JDE)是必要的工具,它包含了一整套用于创建、调试和测试黑莓设备上J2ME应用程序的工具。 7. **ProGuard**:虽然不是特定于J2ME,...

    J2ME小游戏J2ME小游戏J2ME小游戏上,下为另一部分

    J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏

    j2me 开发工具的使用

    **J2ME开发工具的使用** Java 2 Micro Edition(J2ME)是Java平台的一个子集,专门设计用于资源有限的嵌入式设备,如移动电话、智能家电和手持设备。在J2ME开发中,选择合适的工具是至关重要的,它们能够帮助开发者...

    j2me反编译工具【超强】

    4. **逆向工程**:在安全分析或兼容性测试中,反编译工具有助于理解应用程序的行为。 尽管这些工具为开发者提供了便利,但必须注意,未经许可反编译他人的软件可能违反了版权法。在进行反编译之前,确保你有合法的...

    J2ME开发详解工具篇

    资源名称:J2ME开发详解工具篇J2ME开发详解-工具篇,相当基础的文章,主要是根据目前比较热门的手机,像诺基亚、西门子、摩托罗拉等品牌手机程序的IDE开发工具,主要讲解配置及一些基础知识。 资源太大,传百度网盘...

    J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏下,上为另一部分

    J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏J2ME小游戏

    J2ME的编译工具

    **J2ME编译工具——Antenna** J2ME(Java 2 Micro Edition)是Java平台的一个子集,主要用于开发和部署在移动设备、嵌入式系统等资源有限的环境中运行的应用程序。为了构建和管理J2ME项目,开发者通常会使用特定的...

    J2ME无线开发工具包(共2个分卷).part1

    J2ME无线开发工具包(共2个分卷).part1

    J2ME开发工具篇.zip

    J2ME WTK由Sun Microsystems(现为Oracle)开发,包含了开发、测试和部署J2ME应用所需的工具。它提供了模拟器,允许开发者在没有实际设备的情况下测试应用。WTK还提供了丰富的API文档和示例代码,便于学习和参考。 ...

    J2ME无线开发工具包(共2个分卷).part2

    J2ME无线开发工具包(共2个分卷).part2

    J2me实用工具20合1

    J2me实用工具20合1

    J2ME游戏开发地址制作工具

    总的来说,MapWin1411是J2ME游戏开发者的重要辅助工具,它简化了地图制作过程,让开发者能更专注于游戏逻辑和玩法的设计,提升游戏的品质和玩家体验。通过熟练掌握这款工具,开发者可以创造出丰富多彩的移动游戏世界...

    J2ME记录库工具类RecordStoreUtil

    实用J2ME记录库工具类,在很多代码中都要用到

    j2me 心理测试 小程序 源码

    心理测试小程序是一种基于J2ME技术的应用,通常包含一系列问题,用于评估用户的性格、情绪状态或其他心理特征。这种程序可以提供娱乐性,也可以作为自我了解或心理健康监测的工具。由于描述中提到是初学者所编写,...

    J2ME 经典小游戏

    **J2ME经典小游戏** Java 2 Micro Edition(J2ME)是Java平台的一个子集,主要用于嵌入式设备和移动设备,特别是早期的智能手机。J2ME为开发者提供了在小型设备上创建应用程序和游戏的框架。这个压缩包中的"J2ME...

Global site tag (gtag.js) - Google Analytics