japsperDesign整合自己封装的,二维码扩展包,可以自定义版本和容错率

1.效果图

图片效果图

2.具体设计图

3.详细分析

 --设置长宽的时候注意你看到的不一定是真的,要下拉,左右拉才行,才能看到真正的长宽高

具体代码:com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage( new com.google.zxing.qrcode.QRCodeWriter().encodeLY(new String(($F{物料编码}+'_'+$F{供应商编码}+'_'+$F{供应商批次}+'-'+$F{最小包装件数}+'-'+$F{最小包装量}+'-'+$F{基本单位}+'-'+$F{生产日期}+'-'+$F{保质期}).getBytes("UTF-8"),"ISO-8859-1") ,com.google.zxing.BarcodeFormat.QR_CODE,1000,1000,3,'M'))

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这里是一个 Vue 组件,可以生成带有文字和图片的二维码: ```html <template> <div> <canvas ref="qrcodeCanvas"></canvas> </div> </template> <script> import QRCode from "qrcode"; export default { name: "QrcodeWithImageAndText", props: { value: { type: String, required: true }, size: { type: Number, default: 100 }, text: { type: String, default: "" }, textColor: { type: String, default: "#000" }, textSize: { type: Number, default: 16 }, image: { type: String, default: "" }, imageWidth: { type: Number, default: 20 }, imageHeight: { type: Number, default: 20 } }, mounted() { this.generate(); }, methods: { async generate() { try { const canvas = this.$refs.qrcodeCanvas; const url = await QRCode.toDataURL(this.value, { width: this.size }); const img = new Image(); img.src = url; img.onload = () => { canvas.width = img.width; canvas.height = img.height + this.textSize + this.imageHeight; const ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); ctx.font = `${this.textSize}px sans-serif`; ctx.fillStyle = this.textColor; ctx.textAlign = "center"; ctx.fillText( this.text, img.width / 2, img.height + this.textSize + this.imageHeight ); const image = new Image(); image.src = this.image; image.onload = () => { ctx.drawImage( image, img.width / 2 - this.imageWidth / 2, img.height + this.textSize, this.imageWidth, this.imageHeight ); }; }; } catch (err) { console.error(err); } } } }; </script> ``` 这个组件和上一个组件也很相似,但是多了几个属性: - `image`:要添加到二维码下面的图片 URL。 - `imageWidth`:图片的宽度。 - `imageHeight`:图片的高度。 当组件挂载到页面上时,会自动调用 `generate` 方法生成带有文本和图片的二维码,并将其绘制到一个 `canvas` 元素上。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值