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

17
LINES

< > BotCompany Repo | #1016032 // imageToTiles

JavaX fragment (include)

// m = cols, n = rows
static L<BufferedImage> imageToTiles(BufferedImage img, int m, int n) {
  new L<BufferedImage> tiles;
  int w = img.getWidth(), h = img.getHeight();
  if (m > w || n > h)
    fail("Too many tiles (" + m + "/" + n + ") for image of size " + w + "*" + h);
    
  for y to n: {
    int y1 = y*h/n, y2 = (y+1)*h/n;
    for x to m: {
      int x1 = x*w/m, x2 = (x+1)*w/m;
      Rect r = /*rectMinSize(1, 1,*/ rectFromPoints(x1, y1, x2, y2)/*)*/;
      tiles.add(clipBufferedImage(img, r));
    }
  }
  ret tiles;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1016032
Snippet name: imageToTiles
Eternal ID of this version: #1016032/5
Text MD5: 984094cd82c08af342d372eb58a79c00
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-03 02:26:48
Source code size: 547 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 403 / 422
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1016661 - tileRects
#1020189 - rgbImageToFixedSizeTiles (drops tiles that are too small)
#1020217 - tilesToImage - TODO: varying tile sizes
#1020678 - imageToRoughlyFixedSizeTiles
#1020681 - imageToTiles_twoLevelList