Java多个图片合并

1. thumbnailator工具类,依赖如下:

net.coobird

thumbnailator

0.4.8



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( );

你可能感兴趣的:(Java多个图片合并)