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

33
LINES

< > BotCompany Repo | #1037264 // BinaryImageToString

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

Libraryless. Click here for Pure Java version (14364L/83K).

1  
srecord noeq BinaryImageToString(IBinaryImage img) {
2  
  settable S format = "$(width)x$(height)-$(hex)";
3  
  
4  
  simplyCached Image2B renderedImage() {
5  
    ret img == null ?: img.toImage2B();
6  
  }
7  
  
8  
  private S lazyReplace(S s, S pattern, IF0 replacement) {
9  
    if (contains(s, pattern))
10  
      s = replace(s, pattern, strOrEmpty(replacement!));
11  
    ret s;
12  
  }
13  
  
14  
  S get() {
15  
    if (img == null) null;
16  
    
17  
    S s = format;
18  
    s = lazyReplace(s, "$(width)", -> img.getWidth());
19  
    s = lazyReplace(s, "$(height)", -> img.getHeight());
20  
    s = lazyReplace(s, "$(hex)", -> hexPixels());
21  
    ret s;
22  
  }
23  
  
24  
  S hexPixels() {
25  
    var img = this.renderedImage();
26  
    byte[] pixels = img.pixels;
27  
    int n = pixels.length;
28  
    
29  
    while (n > 1 && pixels[n-1] == 0) --n;
30  
31  
    ret bytesToHex(pixels, 0, n);
32  
  }
33  
}

Author comment

Began life as a copy of #1035835

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): gjtlkbvenryc, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1037264
Snippet name: BinaryImageToString
Eternal ID of this version: #1037264/10
Text MD5: 7f1042812dd8f1d2581a0b922a254682
Transpilation MD5: c3255843384925aec68756429fb44064
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-11-13 19:34:42
Source code size: 834 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 129 / 229
Version history: 9 change(s)
Referenced in: [show references]