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

33
LINES

< > BotCompany Repo | #1036004 // PatchworkImage

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9561L/54K).

sclass PatchworkImage<A> extends AbstractWAndH is MakesBufferedImage {
  new L<Patch> patches;
  settable Color backgroundColor = grayToColor(0.9);
  
  class Patch {
    Rect bounds;
    BufferedImage image;
    settable A userValue;
    
    *(Rect *bounds, BufferedImage *image) {}
  }
  
  *() {}
  *(int w, int h) { super(w, h); }
  
  void addPatch(BufferedImage image, Pt etc p, A userValue) {
    addPatch(p, image, userValue);
  }
  
  void addPatch(Pt etc p, BufferedImage image, A userValue) {
    patches.add(new Patch(
      rect(p.x, p.y, image.getWidth(), image.getHeight()),
      image)
      .userValue(userValue));
  }
  
  public BufferedImage getBufferedImage() {
    BufferedImage out = newBufferedImage(w(), h(), backgroundColor);
    for (patch : patches)
      copyBufferedImage(patch.image, out, topLeft(patch.bounds));
    ret out;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036004
Snippet name: PatchworkImage
Eternal ID of this version: #1036004/9
Text MD5: 2923a053ade4c56fb0222b4b25be3598
Transpilation MD5: f76f4538c5f89953d464fb0b7aecb6f3
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-23 16:57:44
Source code size: 896 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 143 / 244
Version history: 8 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)