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

44
LINES

< > BotCompany Repo | #1019873 // Record GIF from Screen Spike [OK]

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

Libraryless. Click here for Pure Java version (15223L/108K).

!7

module RecordGIFSpike > DynSingleFunctionWithPrintLog {
  double sleepBefore = 5, recordForSeconds = 10, frameRate = 10;
  Rect area;
  
  S switchableFields() { ret "sleepBefore recordForSeconds frameRate"; }
  
  void doIt {
    // TODO: delete gif on interruption
    
    runInterruptibly(voidfunc(final Runnable interrupt) ctex {
      temp AutoCloseable action = dm_currentAction("Will record GIF from screen in " + n2(sleepBefore, "second") + "...",
        r { print("INTERRUPTED"); callF(interrupt) });
      print("Sleeping for " + sleepBefore + " before recording GIF...");
      sleepSeconds(sleepBefore);
      call(action, 'setText, "Recording GIF");
      Rect r = or(area, rect(screenWidth()/2-100, 0, 200, 100));
      GifSequenceWriter writer = null;
      long start = sysNow();
      File f = javaxDataDir("Recorded GIFs", ymd_minus_hms() + ".gif");
      temp ImageOutputStream out = fileImageOutputStream(f);
      int delay = iround(1000/frameRate);
      int i = 0;
      while (elapsedMS(start) < toMS(recordForSeconds)) {
        BufferedImage img = shootScreenArea_possiblyBroken(r);
        if (writer == null)
          writer = GifSequenceWriter(out, img.getType(), delay, true);
        writer.writeToSequence(img);
        ++i;
        long slept = sleepUntilSys(start+delay*i);
        print("Wrote image " + i + " (leeway: " + slept + " of " + delay + " ms" + ")");
      }
      close(writer);
      print("Done writing " + fileInfo(f));
    });
  }
  
  // API
  
  void useAreaOfModule(O module) {
    setField(area := toRect(boundsOnScreen(dm_frame(module))));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019873
Snippet name: Record GIF from Screen Spike [OK]
Eternal ID of this version: #1019873/29
Text MD5: 4c93eb4ea90efd6574af7457a0375166
Transpilation MD5: 303175c8402f7c0c0d000cb75d14c2f2
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-02 00:24:53
Source code size: 1651 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 791 / 1199
Version history: 28 change(s)
Referenced in: [show references]