资源简介
Java根据链接生成二维码,用于微信朋友圈分享后扫一扫跳转页面,可以携带参数。
![](http://www.nz998.com/pic/55952.jpg)
代码片段和文件信息
package llj.mf.utils;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.filechooser.FileSystemView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
public class QrCodeUtil {
public static void main(String[] args) {
String url = “http://baidu.com“;
String path = FileSystemView.getFileSystemView().getHomeDirectory() + File.separator + “testQrcode“;
String fileName = new SimpleDateFormat(“yyyyMMddHHmmss“).format(new Date()) + “.jpg“;
createQrCode(url path fileName);
}
public static String createQrCode(String url String path String fileName) {
try {
Map hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET “UTF-8“);
BitMatrix bitMatrix = new MultiFormatWriter().encode(url BarcodeFormat.QR_CODE 400 400 hints);
File file = new File(path fileName);
if (file.exists() || ((file.getParentFile().exists() || file.getParentFile().mkdirs()) && file.createNewFile())) {
writeToFile(bitMatrix “jpg“ file);
System.out.println(“搞定:“ + file);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
static void writeToFile(BitMatrix matrix String format File file) throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image format file)) {
throw new IOException(“Could not write an image of format “ + format + “ to “ + file);
}
}
static void writeToStream(BitMatrix matrix String format OutputStream stream) throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image format stream)) {
throw new IOException(“Could not write an image of format “ + format);
}
}
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private static BufferedImage toBufferedImage(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width height BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x y matrix.get(x y) ? BLACK : WHITE);
}
}
return image;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-04-16 11:38 qrcode\
文件 538421 2016-08-10 12:00 qrcode\core-3.1.0.jar
文件 2558 2017-04-16 11:33 qrcode\QrCodeUtil.java
- 上一篇:社团活动学分管理系统
- 下一篇:android蓝牙与全站仪、单片机数据交互
相关资源
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
- [免费]java实现有障碍物的贪吃蛇游戏
- java Servlet投票实例
- 操作系统作业 (pv,作业管理,等5个
- 基于C/S架构考试系统(Java)
评论
共有 条评论