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

19
LINES

< > BotCompany Repo | #1004270 // copyImage - clone a BufferedImage

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

Transpiled version (4693L) is out of date.

// this copies to RGBA
static BufferedImage copyImage(Image img) {
  if (img == null) null;
  if (img cast BufferedImage)
    ret copyImage(img);
  int w = img.getWidth(null), h = img.getHeight(null);
  BufferedImage bi = newBufferedImage(w, h);
  drawImage(bi, img);
  ret bi;
}

// this one stays in color model. inconsistent i guess
static BufferedImage copyImage(BufferedImage bi) {
  if (bi == null) null;
  ColorModel cm = bi.getColorModel();
  boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
  WritableRaster raster = bi.copyData(bi.getRaster().createCompatibleWritableRaster());
  return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004270
Snippet name: copyImage - clone a BufferedImage
Eternal ID of this version: #1004270/5
Text MD5: c0a9e3c417aa6c09ce17c27d49772df5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-27 14:30:45
Source code size: 684 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 568 / 638
Version history: 4 change(s)
Referenced in: [show references]