美文网首页
java 二维码生成(vcard)

java 二维码生成(vcard)

作者: dalongrong | 来源:发表于2017-07-06 10:55 被阅读211次

1. maven 依赖

<dependency>

   <groupId>com.googlecode.ez-vcard</groupId>

   <artifactId>ez-vcard</artifactId>

   <version>0.10.1</version>

</dependency>

<dependency>

   <groupId>com.google.zxing</groupId>

   <artifactId>javase</artifactId>

   <version>3.3.0</version>

</dependency>

<dependency>

   <groupId>com.google.zxing</groupId>

   <artifactId>core</artifactId>

   <version>3.3.0</version>

</dependency>

2. 代码编写

生成

publicstaticvoidqrCode()throwsWriterException,IOException{

StringfilePath="D://";

StringfileName="zxing.png";

Stringcontent=handlerEvent();

intwidth=200;// 图像宽度

intheight=200;// 图像高度

Stringformat="png";// 图像类型

Maphints=newHashMap();

hints.put(EncodeHintType.CHARACTER_SET,"UTF-8");

BitMatrixbitMatrix=newMultiFormatWriter().encode(content,

BarcodeFormat.QR_CODE,width,height,hints);// 生成矩阵

Pathpath=FileSystems.getDefault().getPath(filePath,fileName);

MatrixToImageWriter.toBufferedImage(bitMatrix);

MatrixToImageWriter.writeToPath(bitMatrix,format,path);// 输出图像

}

vcard 生成

publicstaticStringhandlerEvent(){

VCardcard=newVCard();

card.addEmail(newEmail("1141591465@qq.com"));

Addressorgial=newAddress();

orgial.addParameter("name","dalong");

card.addAddress(newAddress(orgial));

card.addExpertise("软件开发");

Nicknamenickname=newNickname();

nickname.addParameter("姓名","荣锋亮");

card.addNickname(newNickname(nickname));

card.setNickname("大龙");

card.setCategories("北京");

card.setMailer("男");

card.setGeo(116.419791,39.936404);

card.setOrganization("北京公司");

card.setProductId("beijing");

card.setClassification("开发");

Agentagent=newAgent("beijing");

card.setAgent(agent);

card.addExtendedProperty("TEL","XXXXXXXXXXXXX");

Gsonjson=newGson();

returncard.write();

}

3. 结果

4. 微信扫描结果

相关文章

网友评论

      本文标题:java 二维码生成(vcard)

      本文链接:https://www.haomeiwen.com/subject/enchhxtx.html