1.代码

  见文末推荐

2.测试

  测试1:生成base64码

public static void main(String[] args) throws Exception {
String data = "http://www.cnblogs.com/Marydon20170307";
File logoFile = new File(QRcodeUtils.class.getResource("ewm.jpg").getPath());
BufferedImage image = QRcodeUtils.createQRCodeWithLogo(data, logoFile);
String base64 = QRcodeUtils.writeToString(image);
System.out.println(base64);
}

  页面调用:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAARAUlEQVR42u2d23NT1xXGeWkmQHxj
TBPIYxmSvqcMkDwF3LcGQi/PIeTW9g8AkkAymabTp870McFIlm0uzQUDAduQNwwOAWwD1tUk8UUX
OwMYSzq62ZJW17e2jpJMyxRiHckya8+ckXx8fM5B+8da3/722kcrSJs2B9oK/Qi0KVjaFCxtCpY2
bQqWNgVLm4KlTZuCpU3B0qZgadOmYGlTsLQpWNq0KVjaFCxtCpY2bQqWNgVLm4K1iJOtWFHx7X7n
f9j9D3L+BznnYo6v5r9rMZ+zgqVgKVgKloJVEbCcOE+l4KjU+St1/05D7/R5FCwFS8FSsBSsimud
h93/sJqvXvSK05pSwVKwFCwFS8GqO7AqpVcWo2mcuJYT//EULAVLwVKwFKxlD5bT2qtWmk81loKl
YClYCtayBKtWzvti7rNSmqlSkKnzrmApWAqWgqX1WES6vw5mCxQsBUvBUoAecbCcbk473U445rXo
1CXRVwqWgqVgKVgKlhOOsBP1W9WcFHfiP4zT96ZgKVgKloKlYDnqaFfKfa4mcEvB8a/U7EXdaCwF
S8FSsBSs+hwVOj0Ur9U5F9ORTpcdOz15r2ApWAqWgqVgVQ2saloMtdKL1Vysu6ycdwVLwVKwFKz6
dN4rNSyvFWRLQTNV06ZRsBQsBUvBUrDqApr/92EVshGanJwkX+AK+cYGaWy8j8Ym++jWRB/NRftl
S3u7KeU9Vt4XD/dSPHKeUoEusrxdlPMe55/7aZb34/f3In1kTZ2n677DNOw/TKFIB4X4b4PJThqL
d1HEOktzODbcJ/vHxnvl3KGJXvrmO7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5KFh1CBYK6bCgwl7SLp2NjpYV0v3lERp+Byd8cOLD
cl18urRUHj4VJpUBkowaS8vlBSqsKZSVPgYqQGpHoh+g9pQjVSDsKQOH+0oVrilYlQTLiQ/ifx2L
B5vNLgxIJxrIzJNnAJX9ADZTaWAil1gSpcgTlOdlHS1XocoSe36F445XRDacwx4YBEsC3QYqWBoZ
YkGH/TvzSCWzAjpX9P/kwWsP+2+vFBzL9svGnQTLqQftO100p2ApWApWrcGq1D/S6Q+0ml9b4sT+
Sv2tgqVgKVgKloLlaM524tuqnP4STSc6yYnnvDv9NSoKloKlYClYClbFh69OrtJZios5q/nkvlo3
BUvBUrAULAXLkWG807DW6t6qqbGW7RP9FCwFS8FSsJYGWI7n7TqxFWrV8UtJqylYCpaCpWA9omDV
6nuOnf4Qq2k9OK1Zl+2jIhUsBUvBUrDq03mv1Xmq+YwJJ8qjK3UPde+8K1gKloKlYNWn816rb7eq
5oqaat5/NcFVsBQsBUvBUrCWFFiL2V9rV7ran6eCpWApWAqWgvXIgvWwH+hS0H+1sjYULAVLwVKw
FKy6c96d7iQnLAanZwVqDZOCpWApWAqWglVVZ7yaiz9rtTi2VjMECpaCpWApWAqWNm0KljYFS5uC
pU2bgqVNwdKmYGnTpmBpU7C0KVjatClY2hQsbQqWNm0KljYFS5uCpU2bgqVNwdKmYGnTpmBpWwrt
PzS0PEBfvLClAAAAAElFTkSuQmCC" />

  效果展示:

  说明:源代码生成的图片格式已经改成了JPG,这里测试的是PNG,自己记得修改!

2018/11/29

  测试2:生成图片

public static void main(String[] args) {
String data = "Marydon";
// 不带logo
BufferedImage image = createQRCode(data);
String fileName = "博客园";
File qrcodeFile = new File("d:/" + fileName + ".png");
ZxingQrcode.writeToFile(image, qrcodeFile); // 带logo
File logoFile = new File("D:\\ewm.jpg");
image = createQRCodeWithLogo(data, logoFile);
fileName = "博客园2";
qrcodeFile = new File("d:/" + fileName + ".png");
ZxingQrcode.writeToFile(image, qrcodeFile); }

  说明:生成的二维码图片如果它的上级目录不存在,会创建失败!

qrcodeFile = new File("d:/测试/" + fileName + ".png");
// 文件夹不存在,自动创建文件夹
if (!qrcodeFile.exists()) {
qrcodeFile.mkdirs();
}

 

 

java 生成二维码后叠加LOGO并转换成base64的更多相关文章

  1. java生成二维码(带logo)

    之前写过一篇不带logo的二维码实现方式,採用QRCode和ZXing两种方式 http://blog.csdn.net/xiaokui_wingfly/article/details/3947618 ...

  2. 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间

    生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...

  3. java 生成二维码、可带LOGO、可去白边

      1.准备工作 所需jar包: JDK 1.6: commons-codec-1.11.jar core-2.2.jar javase-2.2.jar JDK 1.7: commons-codec- ...

  4. 利用JAVA生成二维码

    本文章整理于慕课网的学习视频<JAVA生成二维码>,如果想看视频内容请移步慕课网. 维基百科上对于二维码的解释. 二维条码是指在一维条码的基础上扩展出另一维具有可读性的条码,使用黑白矩形图 ...

  5. 二维码相关---java生成二维码名片,而且自己主动保存到手机通讯录中...

    版权声明:本文为博主原创文章,未经博主credreamer 同意不得转载 违者追究法律责任. https://blog.csdn.net/lidew521/article/details/244418 ...

  6. java生成二维码的几个方法

    1: 使用SwetakeQRCode在Java项目中生成二维码 http://swetake.com/qr/ 下载地址 或着http://sourceforge.jp/projects/qrcode/ ...

  7. php--------php库生成二维码和有logo的二维码

    php生成二维码和带有logo的二维码,上一篇博客讲的是js实现二维码:php--------使用js生成二维码. 今天写的这个小案例是使用php库生成二维码: 效果图:        使用了 php ...

  8. 使用PHP生成二维码支持自定义logo

    require_once 'phpqrcode/phpqrcode.php'; //引入类库 $text = "https://www.baidu.com/";//要生成二维码的文 ...

  9. java生成二维码打印到浏览器

    java生成二维码打印到浏览器   解决方法: pom.xml的依赖两个jar包: <!-- https://mvnrepository.com/artifact/com.google.zxin ...

随机推荐

  1. 获得手机当前的ip地址

    package com.kale.floating.net; import java.net.Inet4Address; import java.net.InetAddress; import jav ...

  2. Oracle行列转换小结

    目录结构如下:行转列列转行[一].行转列 1.1.初始测试数据 表结构:TEST_TB_GRADE Sql代码 create table TEST_TB_GRADE (   ID        NUM ...

  3. [Web 前端 ] Jquery attr()方法 获取或修改 对象的属性值

    cp from : https://blog.csdn.net/gf771115/article/details/18086707 jquery中用attr()方法来获取和设置元素属性,attr是at ...

  4. HTML5 本地文件操作之FileSystemAPI实例(二)

    文件操作实例整理二 1.删除文件.复制文件.移动文件 //获取请求权限 window.requestFileSystem = window.requestFileSystem || window.we ...

  5. C#和java之间的一些差异与共性

    C#与java之间的一些共性和差异整理 隐藏:与java中的重写几乎一致,但是需要添加new关键字让编译器知道,否则会有警告 虚方法:1.声明为virtual的方法就是虚方法,在子类中使用overri ...

  6. linux中断

    [一].中断底半部 1. 软中断    --->>>  执行在中断上下文  --->>>  会被中断打断,不会被软中断或进程打断  --->>> ...

  7. Binary Tree ZigZag Level Order Traversal leetcode java

    题目: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from lef ...

  8. 大规模SNS中兴趣圈子的自动挖掘

    转自:http://www.infoq.com/cn/articles/zjl-sns-automatic-mining 一.为何要在大规模SNS中挖掘兴趣圈子 随着国外的facebook.twitt ...

  9. Spark Structured Streaming:将数据落地按照数据字段进行分区方案

    方案一(使用ForeachWriter Sink方式): val query = wordCounts.writeStream.trigger(ProcessingTime(5.seconds)) . ...

  10. 使用 Edit + MASM 5.0 编译器 + Linker 连接器

    其实这种方式是很简单的,只是很麻烦,因为简单而且麻烦, 所以我采用尽可能的将截图传上来,然后稍加注解的方式进行介绍, 软件准备: 需要 MASM 5.0 或者以上的汇编编译器 首先,是要编辑汇编源代码 ...