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

22
LINES

< > BotCompany Repo | #1007272 // makeRoundedCorner - add rounded, transparent corner to BufferedImage

JavaX fragment (include)

1  
import java.awt.geom.*;
2  
3  
static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) {
4  
  int w = image.getWidth();
5  
  int h = image.getHeight();
6  
  BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
7  
  Graphics2D g2 = output.createGraphics();
8  
9  
  // fake soft-clipping by first drawing the desired clip shape
10  
  // in fully opaque white with antialiasing enabled...
11  
  g2.setComposite(AlphaComposite.Src);
12  
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
13  
  g2.setColor(Color.WHITE);
14  
  g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius));
15  
16  
  // ... then compositing the image on top,
17  
  // using the white shape from above as alpha source
18  
  g2.setComposite(AlphaComposite.SrcAtop);
19  
  g2.drawImage(image, 0, 0, null);
20  
  g2.dispose();
21  
  ret output;
22  
}

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: #1007272
Snippet name: makeRoundedCorner - add rounded, transparent corner to BufferedImage
Eternal ID of this version: #1007272/2
Text MD5: 080f0dda102d405c35317f761a3ce064
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 14:44:45
Source code size: 871 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 540 / 546
Version history: 1 change(s)
Referenced in: [show references]