Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

86
LINES

< > BotCompany Repo | #1016673 // Live WebCam [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 2547K of libraries. Click here for Pure Java version (13885L/72K).

1  
!7
2  
3  
// Trying to dispose of web cam properly when module is exited
4  
// (see https://github.com/sarxos/webcam-capture/issues/848)
5  
6  
cm LiveWebCam > DynSCP {
7  
  transient WebcamPanel panel;
8  
  int fpsLimit = -1;
9  
  bool autoStart;
10  
  switchable bool alwaysOnTop; // TODO: alwaysOnTop without restart
11  
  
12  
  enhanceFrame {
13  
    minimalFrameSize(f/JInternalFrame, 320, 240);
14  
    internalFramePopupMenuItem(f, "Save to AI Album",
15  
      rThread { dm_saveToAIAlbum(getImage()) });
16  
    internalFramePopupMenuItem(f, "Set FPS...", r {
17  
      final JTextField tf = jtextfield(str(fpsLimit));
18  
      showFormTitled("Set FPS Limit",
19  
        "FPS Limit (-1 for no limit, 0 for no updates):", tf,
20  
        rThread { setFPSLimit(parseInt(gtt(tf))) });
21  
    });
22  
    dm_boolFieldMenuItem(f, 'autoStart);
23  
    internalFramePopupMenuItem(f, "Natural size", r dm_packFrame);
24  
    if (alwaysOnTop) dm_alwaysOnTop(f);
25  
  }
26  
27  
  JComponent visualize2() {
28  
    ret jcenteredbutton("Start", rThread startIt);
29  
  }
30  
  
31  
  afterVisualize { if (autoStart) startIt(); }
32  
  
33  
  void startIt {
34  
    selectWebCam(vf<Webcam> selectCam);
35  
  }
36  
  
37  
  void startPreferredOrSelect {
38  
    selectWebCam_withPreferred(vf<Webcam> selectCam);
39  
  }
40  
  
41  
  void selectCam(Webcam cam) enter {
42  
    final WebcamPanel panel = new WebcamPanel(cam, false);
43  
    LiveWebCam.this.panel = panel;
44  
    bindToComponent(panel, null, r { panel.stop() });
45  
    updateFPSLimitInPanel();
46  
    setComponent(panel);
47  
    //dm_packFrame();
48  
  }
49  
  
50  
  void stopIt {
51  
    if (panel == null) ret;
52  
    panel.stop();
53  
  }
54  
  
55  
  void cleanMeUp {
56  
    var cam = panel?.getWebcam();
57  
    if (cam != null) {
58  
      print("Disposing of web cam");
59  
      call(cam, "dispose");
60  
    }
61  
  }
62  
  
63  
  BufferedImage getImage() {
64  
    ret imageFromWebcamPanel(panel);
65  
  }
66  
  
67  
  void setFPSLimit(int limit) {
68  
    setField(fpsLimit := limit);
69  
    updateFPSLimitInPanel();
70  
  }
71  
  
72  
  void updateFPSLimitInPanel {
73  
    setModuleName((fpsLimit >= 0 ? fpsLimit + " FPS - " : "") + "Live WebCam");
74  
    if (panel == null) ret;
75  
    panel.stop();
76  
    if (fpsLimit == 0) ret; // TODO - want to keep last image there anyway
77  
    panel.setFPSDisplayed(fpsLimit < 0);
78  
    if (fpsLimit > 0) panel.setFPSLimit(fpsLimit);
79  
    panel.setFPSLimited(fpsLimit > 0);
80  
    panel.start();
81  
  }
82  
  
83  
  bool isWebCamLive() {
84  
    ret panel != null && fpsLimit != 0;
85  
  }
86  
}

Author comment

Began life as a copy of #1013489

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wdffvflfhhdx

No comments. add comment

Snippet ID: #1016673
Snippet name: Live WebCam [Dyn Module]
Eternal ID of this version: #1016673/32
Text MD5: a4b2a66eac77e20e94b146f3dfec3770
Transpilation MD5: 0a2c71aa1627e38e2ba29db2e5fd59b1
Author: stefan
Category: javax / desktop / camera
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-25 17:08:18
Source code size: 2387 bytes / 86 lines
Pitched / IR pitched: No / No
Views / Downloads: 592 / 3034
Version history: 31 change(s)
Referenced in: [show references]