1. thumbnailator工具類缺厉,依賴如下:
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
2. 代碼如下:
BufferedImage image1= Thumbnails.of(new URL(image1)).size(90,90).asBufferedImage();
BufferedImage image2= Thumbnails.of(new URL(image2)).size(130,130).asBufferedImage();
BufferedImage textImage = Thumbnails.of(handleTextWaterMark(text)).size(300,100).asBufferedImage();
Thumbnails.of(new URL(image)).size(720,1280)
.watermark(new Coordinate(30,30), image1,1f)
.watermark(new Coordinate(160,30), image2,1f)
.watermark(Positions.BOTTOM_RIGHT, textImage?,1f)
.toFile(posterFile);
Font font =new Font("微軟雅黑", Font.BOLD,26);
BufferedImage image =new BufferedImage(300,100, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics( );
image = g.getDeviceConfiguration( ).createCompatibleImage(300,100, Transparency.TRANSLUCENT);
g = image.createGraphics( );
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(Color.black);
g.setFont(font);
g.drawString(nickName,0,50);
g.setColor(new Color(0,0,0));
g.setFont(new Font("微軟雅黑", Font.CENTER_BASELINE,25));
g.dispose( );