Manager.createPlayer("capture://video") 建立 Player。player.getControl("VideoControl") 取得 VideoControl。VideoControl.initDisplayMode(mode, arg) 設定顯示模式。getSnapshot(null) 取得 PNG 圖片位元組陣列。Form 等高階 UI 容器。arg:null (單一 UI 平台) 或完整類名字串 (多 UI 平台)。Item),直接 form.append()。Player p = Manager.createPlayer("capture://video");
p.realize();
VideoControl vc = (VideoControl) p.getControl("VideoControl");
if (vc != null) {
Item videoItem = (Item) vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
form.append(videoItem); // 當前類繼承 Form
}
p.start();
Canvas 或子類。arg:Canvas 實例 (this)。null。vc.setVisible(true)。setDisplayLocation(x, y) 與大小 setDisplaySize(w, h)。Player p = Manager.createPlayer("capture://video");
p.realize();
VideoControl vc = (VideoControl) p.getControl("VideoControl");
if (vc != null) {
vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this); // 繼承 Canvas
vc.setVisible(true);
vc.setDisplaySize(176, 144);
vc.setDisplayLocation(0, 0);
}
p.start();
getSourceWidth(), getSourceHeight()getDisplayWidth(), getDisplayHeight()getDisplayX(), getDisplayY()注意:setDisplaySize 僅影響預覽畫面大小,不影響 getSnapshot() 取得的原始解析度。
byte[] pngData = vc.getSnapshot(null); // null = PNG 格式
Image img = Image.createImage(pngData, 0, pngData.length);
// 後續可存入 RMS、顯示於 UI、或透過 HTTP 上傳伺服器
西門子 SX1 遊戲《打蚊子》:背景為攝像頭即時畫面,玩家搖晃手機,遊戲計算移動方向調整蚊子位置與瞄準器,極具創新性。