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

27
LINES

< > BotCompany Repo | #1007275 // cutImageToCircle

JavaX fragment (include)

1  
import java.awt.geom.*;
2  
3  
static BufferedImage cutImageToCircle(S imageID) {
4  
  ret cutImageToCircle(loadImage2(imageID));
5  
}
6  
7  
static BufferedImage cutImageToCircle(BufferedImage image) {
8  
  int w = min(image.getWidth(), image.getHeight());
9  
  ret cutImageToCircle(image, w);
10  
}
11  
12  
static BufferedImage cutImageToCircle(BufferedImage image, int w) {
13  
  int h = w;
14  
  image = img_getCenterPortion(image, w, w);
15  
  BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
16  
  Graphics2D g2 = output.createGraphics();
17  
18  
  g2.setComposite(AlphaComposite.Src);
19  
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
20  
  g2.setColor(Color.WHITE);
21  
  g2.fill(new Ellipse2D.Float(0, 0, w, h));
22  
23  
  g2.setComposite(AlphaComposite.SrcAtop);
24  
  g2.drawImage(image, 0, 0, null);
25  
  g2.dispose();
26  
  ret output;
27  
}

Author comment

Began life as a copy of #1007272

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: #1007275
Snippet name: cutImageToCircle
Eternal ID of this version: #1007275/4
Text MD5: 240928fc67090df6afa66cf877647bd7
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-14 18:02:40
Source code size: 861 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 469 / 507
Version history: 3 change(s)
Referenced in: [show references]