📄 camerademo.java
字号:
/* * * Copyright (c) 2007, Sun Microsystems, Inc. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */import java.io.*;import java.util.Date;import java.util.Enumeration;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import javax.microedition.media.*;import javax.microedition.media.control.VideoControl;import javax.microedition.amms.*;import javax.microedition.amms.control.camera.*;import javax.microedition.io.file.*;import javax.microedition.io.*;public class CameraDemo extends MIDlet implements CommandListener, ItemStateListener{ private Player player; private CameraControl camCtrl = null; private VideoControl vidCtrl = null; private ExposureControl expCtrl = null; private FlashControl flsCtrl = null; private FocusControl fcsCtrl = null; private ZoomControl zomCtrl = null; private SnapshotControl snpCtrl = null; private Command exitCommand = new Command("Exit", Command.ITEM, 1); private Command backCommand = new Command("Back", Command.BACK, 1); private Command backToBrowserCommand = new Command("Back", Command.BACK, 1); private Command deleteImageFile = new Command("Delete from disk", Command.ITEM, 1); private final Command snapCommand = new Command("Snapshot", Command.STOP, 1); private final Command stopShottingCommand = new Command("Stop Shooting", Command.ITEM, 1); private final Command saveSnapCommand = new Command("Save it", Command.STOP, 1); private final Command deleteSnapCommand = new Command("Delete it", Command.ITEM, 1); private final Command changeExposureCommand = new Command("Choose exposure modes", Command.ITEM, 3); private final Command enabledShutterFeedbackCommand = new Command("Enable shutter feedback", Command.ITEM, 2); private final Command disabledShutterFeedbackCommand = new Command("Disable shutter feedback", Command.ITEM, 2); private final Command setSupportedF_StopsCommand = new Command("Change F_Stop number", Command.ITEM, 4); private final Command setFlashModeCommand = new Command("Set flash mode", Command.ITEM, 5); private final Command setSnapshotCommand = new Command("Snapshot setting", Command.ITEM, 1); private final Command viewGalleryCommand = new Command("View gallery", Command.ITEM, 6); private final Command displayCommand = new Command("Display", Command.ITEM, 6); private final Command setFocusCommand = new Command("Focus settings", Command.ITEM, 7); private final Command setZoomCommand = new Command("Zoom settings", Command.ITEM, 8); private Display display; private Form vidForm; private Form snapForm; private Item videoItem; private ChoiceGroup exposureModes; private Form exposureModesForm; private ChoiceGroup F_StopsCG; private Form supportedF_StopsForm; private ChoiceGroup flashModes; private ChoiceGroup focusModes; private ChoiceGroup zoomOptModes; private ChoiceGroup zoomDigModes; private Form flashModesForm; private Form focusModesForm; private Form zoomModesForm; private String focusSupportedModes[]; private int focusModesInt[]; private String zoomOptSupportedModes[]; private int zoomOptModesInt[]; private String zoomDigSupportedModes[]; private int zoomDigModesInt[]; private List browser; private Form imageViewer; private FileConnection currImage; private Form snapshotSettingsForm; private ChoiceGroup snapSetDisOrSave; private String[] snapSetOption = {"Display picture on screen", "Save picture to file"}; private ChoiceGroup snapSetFreezeOrConfirm; private String[] snapSetFreezeOption = {"Freeze the viewfinder", "Freeze and confirm", "Save without freezing"}; private TextField burstNum; private int NumOfPic = -2; private boolean savedMessageAppear = false; private static String[] flashAllModes = {"OFF", "AUTO", "AUTO_WITH_REDEYEREDUCE", "FORCE", "FORCE_WITH_REDEYEREDUCE", "FILLIN" }; /* separator character as defined by FC specification */ private final static char SEP = '/'; private String PHOTOS_DIR = null; public CameraDemo() { vidForm = new Form("Camera Player"); display = Display.getDisplay(this); display.setCurrent(vidForm); vidForm.addCommand(exitCommand); vidForm.setCommandListener(this); try { player = Manager.createPlayer("capture://video"); player.prefetch(); player.realize(); vidCtrl = (VideoControl)player.getControl( "VideoControl"); if (vidCtrl != null) { videoItem = (Item)vidCtrl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null); vidCtrl.setDisplaySize(140, 140); vidForm.append(videoItem); } else { System.out.println("Error: Can not create VideoControl"); return; } camCtrl = (CameraControl)player.getControl( "javax.microedition.amms.control.camera.CameraControl"); if (camCtrl != null) { vidForm.addCommand(snapCommand); vidForm.addCommand(changeExposureCommand); vidForm.addCommand(enabledShutterFeedbackCommand); } expCtrl = (ExposureControl)player.getControl( "javax.microedition.amms.control.camera.ExposureControl"); if (expCtrl != null) { vidForm.addCommand(setSupportedF_StopsCommand); } flsCtrl = (FlashControl)player.getControl( "javax.microedition.amms.control.camera.FlashControl"); if (flsCtrl != null) { vidForm.addCommand(setFlashModeCommand); } fcsCtrl = (FocusControl)player.getControl( "javax.microedition.amms.control.camera.FocusControl"); if (fcsCtrl != null) { vidForm.addCommand(setFocusCommand); } zomCtrl = (ZoomControl)player.getControl( "javax.microedition.amms.control.camera.ZoomControl"); if (zomCtrl != null) { vidForm.addCommand(setZoomCommand); } snpCtrl = (SnapshotControl)player.getControl( "javax.microedition.amms.control.camera.SnapshotControl"); if (snpCtrl != null) { vidForm.addCommand(setSnapshotCommand); vidForm.addCommand(viewGalleryCommand); vidForm.addCommand(stopShottingCommand); } } catch (MediaException me) { me.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } public void startApp() { try { player.start(); } catch (MediaException me) { me.printStackTrace(); } } public void pauseApp() { if (camCtrl != null) { stopShooting(); } try { player.stop(); } catch (MediaException me) { me.printStackTrace(); } } public void destroyApp(boolean unconditional) { closePlayer(); notifyDestroyed(); } /* * Respond to commands, including back */ public void commandAction(Command c, Displayable s) { if (savedMessageAppear == true && vidForm.size() > 1) { vidForm.delete(vidForm.size() - 1); savedMessageAppear = false; } if (c == backCommand) { if (snapshotSettingsForm != null && snapshotSettingsForm.isShown() && snapSetFreezeOrConfirm.getSelectedIndex() == 2) { NumOfPic = Integer.parseInt(burstNum.getString()); } else if (focusModesForm != null && focusModesForm.isShown()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -