java生成中间带图片的二维码。

这个博客分享了一个Java工具类,用于生成中间带有图片的二维码。代码直接可用,生成的二维码图片可以方便地集成到项目中。工具类支持设置二维码的格式、尺寸,并提供了在二维码中间插入指定图片的方法。
摘要由CSDN通过智能技术生成

我不喜欢费话,直接上代码!这是一个工具类。 直接烤到项目中就可以用。生成二维码的图片后,就可以直接放到项目中去使用。 方便,简单。 

//第一个类

import java.awt.Color;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.exception.DecodingFailedException;

import com.swetake.util.Qrcode;

    /**
    * java 生成二维码
    * 黑夜
    *
    **/
public class TwoDimensionCode {
private static String imgType = "png";//二维码图片格式
private static int size = 7;//二维码尺寸
private String codeType = "utf-8";

//设置二维码中间图片的宽高
private int imageWidth = 30;
private int imageHeight = 30;
  
    /** 
     * 生成二维码(QRCode)图片 
     * @param content 存储内容 
     * @param imgPath 中间图片路径 
     * @param imgType 图片类型 
     * @param size 二维码尺寸 
     * 
     * @param outpath 输出二维码文件
     */  
    public BufferedImage encoderQRCode(String content, String imgPath, String imgType, int size,String outpath) {  
        try {  
            BufferedImage bufImg = this.qRCodeCommon(content, imgType, size); 
            
       //在二维码中间加入图片
            BufferedImage _bufImg =  createPhotoAtCenter(bufImg,imgPath);
            
            File imgFile = new File(outpath);  
       

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值