java 自定义收款二维码,使用图片融合,自定义文字

1, 输出

原图资源 : 下载原图, CSDN 下载, 无需积分在这里插入图片描述

模版
底图 768 x 1299
在这里插入图片描述
二维码 527*527
在这里插入图片描述

2 代码


import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class 图片合并 {

    public static void main(String[] args) {
        try {
            // 读取底图和二维码图片
            BufferedImage background = ImageIO.read(new File("D:\\tmp\\wechatpay.png"));
            BufferedImage qrCode = ImageIO.read(new File("D:\\tmp\\recode.png"));

            // 设置二维码图片的位置(x, y)
            int x = 121;
            int y = 446;

            // 在底图上绘制二维码图片
            background.getGraphics().drawImage(qrCode, x, y, null);

            // 设置文字内容和位置
            {
                String text = "长沙吴彦祖物业公司";
                Font font = new Font("Microsoft YaHei", Font.BOLD, 36);
                Color color = Color.WHITE;
                int textX = (int) ((background.getWidth() - font.getStringBounds(text, new FontRenderContext(null, true, false)).getWidth()) / 2);
                int textY = 310;

                // 在底图上添加文字
                Graphics2D g2d = background.createGraphics();
                g2d.setFont(font);
                g2d.setColor(color);
                g2d.drawString(text, textX, textY);
                g2d.dispose();
            }
            {
                String text = "ID : 123";
                Font font = new Font("Microsoft YaHei", Font.PLAIN, 36);
                Color color = Color.WHITE;
                int textX = (int) ((background.getWidth() - font.getStringBounds(text, new FontRenderContext(null, true, false)).getWidth()) / 2);
                int textY = 385;

                // 在底图上添加文字
                Graphics2D g2d = background.createGraphics();
                g2d.setFont(font);
                g2d.setColor(color);
                g2d.drawString(text, textX, textY);
                g2d.dispose();
            }
            {
                String text = "> 麓谷企业广场";
                Font font = new Font("Microsoft YaHei", Font.PLAIN, 36);
                Color color = Color.WHITE;
                int textX = (int) ((background.getWidth() - font.getStringBounds(text, new FontRenderContext(null, true, false)).getWidth()) / 2);
                int textY = 446 + 527 + 125;

                // 在底图上添加文字
                Graphics2D g2d = background.createGraphics();
                g2d.setFont(font);
                g2d.setColor(color);
                g2d.drawString(text, textX, textY);
                g2d.dispose();
            }

            // 保存合成后的图片
            ImageIO.write(background, "jpg", new File("D:\\tmp\\output.jpg"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值