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.

1  
// this copies to RGBA
2  
static BufferedImage copyImage(Image img) {
3  
  if (img == null) null;
4  
  if (img cast BufferedImage)
5  
    ret copyImage(img);
6  
  int w = img.getWidth(null), h = img.getHeight(null);
7  
  BufferedImage bi = newBufferedImage(w, h);
8  
  drawImage(bi, img);
9  
  ret bi;
10  
}
11  
12  
// this one stays in color model. inconsistent i guess
13  
static BufferedImage copyImage(BufferedImage bi) {
14  
  if (bi == null) null;
15  
  ColorModel cm = bi.getColorModel();
16  
  boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
17  
  WritableRaster raster = bi.copyData(bi.getRaster().createCompatibleWritableRaster());
18  
  return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
19  
}

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: 496 / 545
Version history: 4 change(s)
Referenced in: [show references]