好吧,那么从...开始
我用了...
BufferedImage source = ImageIO.read(new File("Example.jpg"));
GeneralPath clip = new GeneralPath();
clip.moveTo(65, 123);
clip.lineTo(241, 178);
clip.lineTo(268, 405);
clip.lineTo(145, 512);
clip.closePath();
Rectangle bounds = clip.getBounds();
BufferedImage img = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
clip.transform(AffineTransform.getTranslateInstance(-65, -123));
g2d.setClip(clip);
g2d.translate(-65, -123);
g2d.drawImage(source, 0, 0, null);
g2d.dispose();
ImageIO.write(img, "png", new File("Clipped.png"));
Run Code Online (Sandbox Code Playgroud)
生成...
现在,图像是矩形的,这就是它的工作方式
现在,setClip非常粗糙并且不受任何影响RenderingHints,您可以改用“软剪辑”,这更复杂,但会产生更好的结果。有关更多详细信息,请参阅此示例和此示例
| 归档时间: |
|
| 查看次数: |
2348 次 |
| 最近记录: |