📄 cameraform.java
字号:
/*****************************************************************************
Description: CameraForm
* The cameraForm holds a camera and the camera functionality
Created By: Johan Kateby
@file CameraForm.java
COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2004.
The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
The use of the software is subject to the terms of the end-user license
agreement which accompanies or is included with the software. The software is
provided "as is" and Sony Ericsson specifically disclaim any warranty or
condition whatsoever regarding merchantability or fitness for a specific
purpose, title or non-infringement. No warranty of any kind is made in
relation to the condition, suitability, availability, accuracy, reliability,
merchantability and/or non-infringement of the software provided herein.
*****************************************************************************/
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.lcdui.*;
import java.util.*;
public class CameraForm extends Form implements CommandListener{
private Command captureCommand, backCommand;
private Player myPlayer;
private VideoControl vc;
// The byteArray for storing the image and creating images
private byte[] byteImage;
// the next Display to be displayed when we are done here
private Displayable next;
/** Creates a new instance of CameraCanvas */
public CameraForm(Displayable next)
{
super("Camera");
this.next = next;
captureCommand = new Command("Capture",Command.SCREEN,1);
backCommand = new Command("Back",Command.BACK,1);
this.addCommand(captureCommand);
this.addCommand(backCommand);
this.setCommandListener(this);
initPlayer();
}
private void initPlayer(){
try{
myPlayer = Manager.createPlayer("capture://video");
myPlayer.realize();
// Grab the video control and set it to the current display.
vc = (VideoControl)myPlayer.getControl("VideoControl");
if (vc != null) {
append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));
// sets the size of the viewfinder. This has no impact on the snapshot's size!
vc.setDisplaySize(352,288);
}
myPlayer.start();
}catch(Exception e){
System.out.println("Exception: " + e.toString());
}
}
// Here we a taking the snapshot and send the image data to a ImageForm
private void captureImage()
{
try {
byteImage = vc.getSnapshot(null);
FileConnectionDemoMidlet.display.setCurrent(new ImageSaveForm(byteImage, this)) ;
}catch( Exception e ) {
System.out.println("Exception: " + e.toString());
}
}
public void commandAction(Command c, Displayable s){
// Go back to the FileConnectionMIdlet
// Or taking the picture
if(c==backCommand){
FileConnectionDemoMidlet.display.setCurrent(next);
}
else if (c==captureCommand){
new Thread(new Runnable() {
public void run() {
captureImage();
}
}).start();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -