生成链接二维码

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import java.io.File;
import java.io.IOException;
import java.util.Hashtable;

public class QrCodeUtil {
public static void main(String[] args) throws IOException {
    String text = "www.baidu.com";
    int width = 100;
    int height = 100;
    String format = "png";
    Hashtable hints = new Hashtable();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
    hints.put(EncodeHintType.MARGIN, 2);
    try {
        BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);
        File file = new File("D:/ps/img.png");//在D盘生成二维码图片
        MatrixToImageWriter.writeToFile(bitMatrix, format, file);
    } catch (WriterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在uniapp中生成二维码的方法如下所示: 1. 首先,在uniapp项目中下载源码并解压。 2. 将/components文件夹下的组件复制到项目根目录的/components文件夹下。 3. 在需要生成二维码的页面的vue文件中,添加以下代码: ``` <template> <view style="margin: 40upx;"> <ayQrcode ref="qrcode" :modal="modal_qr" :url="url" @hideQrcode="hideQrcode" :height="300" :width="300" /> </view> </template> <script> import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue" export default { components: { ayQrcode, }, data() { return { // 二维码相关参数 modal_qr: false, url: 'https://pixabay.com/images/search/?order=ec', // 要生成二维码值 } }, onLoad() { let that = this; that.showQrcode(); // 一加载生成二维码 }, methods: { // 展示二维码 showQrcode() { let _this = this; this.modal_qr = true; setTimeout(function() { _this.$refs.qrcode.crtQrCode() }, 50) }, // 传入组件的方法 hideQrcode() { this.modal_qr = false; }, } } </script> ``` 以上代码中,template部分包含了一个ayQrcode组件,这个组件用于生成和展示二维码。在script部分,我们引入了ayQrcode组件,并在data中定义了相关参数。onLoad生命周期函数中调用了showQrcode方法,该方法用于展示二维码。showQrcode方法中触发了crtQrCode方法来生成二维码。hideQrcode方法用于隐藏二维码。 4. 最后,在需要使用生成二维码的页面中添加对应的跳转链接,点击链接后即可生成对应的二维码。 请参考上述步骤进行操作,即可在uniapp中生成链接二维码。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值