📄 camera.he
字号:
class
{
const int CMD_BACK = 1;
const int CMD_CAPTURE = 2;
MenuItem BACK = new MenuItem(CMD_BACK, "Back");
MenuItem CAPTURE = new MenuItem(CMD_CAPTURE, "Capture");
List encTypes = new List()
.add("encoding=jpeg&width=320&height=240")
.add("encoding=jpeg");
Flow flow = null;
Camera camera = null;
void startWidget()
{
setMinimizedView(createMinimizedView("viewMini", getStyle("default")));
}
Shell openWidget()
{
camera = new Camera(getStyle("mini"));
if (!camera.isAvailable()) {
setBubble(null, "Camera not available");
return null;
}
flow = new Flow(getStyle("mini"));
camera.setFlags(VISIBLE|LINEFEED);
camera.setPreferredSize(-100,-100);
flow.add(camera);
return new Shell(flow);
}
//gets called when widget's maximized view is closed
void closeWidget()
{
//remember to close camera if it's still shown
if (camera != null) {
camera.close();
camera = null;
}
}
MenuItem getSoftKey(Shell shell, Component focused, int key)
{
if (key == SOFTKEY_OK && camera != null) {
return CAPTURE;
} else if (key == SOFTKEY_BACK) {
return BACK;
}
return null;
}
void actionPerformed(Shell shell, Component source, int action)
{
if (action == CMD_BACK) {
popShell(shell);
} else if (action == CMD_CAPTURE) {
flow.clear();
//Lets hope that phone supports encoding types listed in
//encTypes. PNG is safe bet as it is mandatory for MIDP
//devices but most camera phones also support JPEG, and
//of course jpeg will pack to smaller image size.
ByteArray imageData = camera.capture(encTypes);
if (imageData == null) {
setBubble(null, "Image capturing failed");
}
camera.close();
camera = null;
Image image = getImage(imageData);
Picture picture = new Picture(getStyle("default"), image);
picture.setPreferredSize(-100, -100);
flow.add(picture);
shell.updateMenu();
flushScreen(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -