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


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

JavaX fragment (include)

import java.awt.geom.*;

static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) {
  int w = image.getWidth();
  int h = image.getHeight();
  BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2 = output.createGraphics();

  // fake soft-clipping by first drawing the desired clip shape
  // in fully opaque white with antialiasing enabled...
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius));

  // ... then compositing the image on top,
  // using the white shape from above as alpha source
  g2.drawImage(image, 0, 0, null);
  ret output;

download  show line numbers  debug dex   

Travelled to 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

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: 283 / 262
Version history: 1 change(s)
Referenced in: [show references]