Java - get Trapezoid clip from an Image

BufferedImage source = ImageIO.read(new File("d:\\design.jpg")); GeneralPath clip = new GeneralPath(); clip.moveTo(0, 0); clip.lineTo(50, 426); clip.lineTo(303, 426); clip.lineTo(353, 0); clip.closePath(); Rectangle bounds = clip.getBounds(); BufferedImage img = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setComposite(AlphaComposite.Clear); g2d.setClip(clip); g2d.drawImage(source, 0, 0, null); g2d.dispose(); ImageIO.write(img, "png", new File("Clipped.png"));
Simple thing I was looking

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.