vCard介紹
vCard是電子名片的文件格式標(biāo)準(zhǔn)。它一般附加在電子郵件之后,但也可以用于其它場(chǎng)合(如在互聯(lián)網(wǎng)上相互交換)熙兔。vCard可包含的信息有:姓名容客、地址資訊、電話(huà)號(hào)碼二跋、URL战惊,logo,相片等同欠。
vCard(或稱(chēng)做Versitcard)最早是由Versit聯(lián)盟于1995年提出的样傍,當(dāng)時(shí)聯(lián)盟成員包括蘋(píng)果公司,AT&T科技(后來(lái)的朗訊)铺遂,IBM及西門(mén)子衫哥。在1996年十二月,格式的擁有權(quán)移至互聯(lián)網(wǎng)郵件聯(lián)盟(IMC)襟锐,此聯(lián)盟是由一些關(guān)注互聯(lián)網(wǎng)電子郵件的公司所組成撤逢。
與vCard一同提出的用于數(shù)據(jù)交換的標(biāo)準(zhǔn)還有vCalendar,但現(xiàn)在被iCalendar所取代粮坞∥萌伲互聯(lián)網(wǎng)郵件聯(lián)盟已經(jīng)聲明它希望“所有的vCalendar開(kāi)發(fā)者利用這些新的開(kāi)放標(biāo)準(zhǔn),并使軟件能夠同時(shí)兼容vCalendar 1.0和iCalendar莫杈』ダ”
vCard標(biāo)準(zhǔn)的2.1版被電子郵件客戶(hù)端廣泛支持。3.0版是一個(gè)包含在RFC 2425和RFC 2426中的IETF標(biāo)準(zhǔn)跟蹤提案筝闹。vCard的常用副檔名是.vcf媳叨。
不同的程序?qū)?strong>vCard標(biāo)準(zhǔn)實(shí)現(xiàn)亦不同。Mac OS X中的Address Book允許把所有聯(lián)系人導(dǎo)出到一個(gè)vcf文件关顷,而Microsoft Outlook只能每人一個(gè)文件糊秆。Linux中KDE的Kontact允許每個(gè)文件導(dǎo)入或?qū)С鲆蝗嘶蚨嗳恕?/p>
vCard文件樣例
BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest
FN:Forrest Gump
ORG:Gump Shrimp Co.
TITLE:Shrimp Man
TEL;WORK;VOICE:(111) 555-1212
TEL;HOME;VOICE:(404) 555-1212
EMAIL;PREF;INTERNET:forrestgump@walladalla.com
REV:20080424T195243Z
END:VCARD
java代碼生成二維碼
- 需要google提供的zxing包生成二維碼,提前準(zhǔn)備好導(dǎo)入到工程中(com.google.zxing.common.BitMatrix)
MatrixToImageWriter類(lèi)
import javax.imageio.ImageIO;
import java.io.File;
import java.io.OutputStream;
import java.io.IOException;
import java.awt.image.BufferedImage;
import com.google.zxing.common.BitMatrix;
public final class MatrixToImageWriter {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private MatrixToImageWriter() {
}
public 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;
}
public 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);
}
}
public 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);
}
}
}
CreQcode類(lèi)
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
public class CreQcode {
public static void main(String[] args) {
try {
// 1.下面是我測(cè)試用的一個(gè)format
// BEGIN:VCARD
// "VERSION:3.0
// N:李德偉
// EMAIL:1606841559@qq.com
// TEL:12345678912
// TEL;CELL:12345678912
// ADR:山東濟(jì)南齊魯軟件園
// ORG:濟(jì)南
// TITLE:軟件工程師
// URL:http://blog.csdn.net/lidew521
// NOTE:呼呼測(cè)試下吧议双。痘番。。
// END:VCARD"
// 2.根據(jù)測(cè)試結(jié)果推理
// ---------------------------------------
// 測(cè)試結(jié)果不加回車(chē)是不行的這樣的話(huà)會(huì)出現(xiàn)問(wèn)題
// 就是掃描出來(lái)以后會(huì)沒(méi)有內(nèi)容
// 這里可以看出,微信解析二維碼的方式
// -------------------------------------------------
// 3.測(cè)試\n可以被二維碼識(shí)別
// 這里也是有原因的,因?yàn)槲⑿艗呙瓒S碼后會(huì)進(jìn)行二次加工,
// 這里加工的時(shí)候,是用java代碼的,因?yàn)槭莂ndroid系統(tǒng),所以在
// java中的回車(chē)是\n,因此這里就要用\n來(lái)分割
String content = "BEGIN:VCARD\n" + "VERSION:3.0\n" + "N:張三\n" + "EMAIL:11111@qq.com\n" + "TEL:15100000000\n" + "ADR:\n" + "ORG:\n" + "TITLE:\n" + "URL:\n" + "NOTE:\n" + "END:VCARD";
String path = "D:/";
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
Map hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 400, 400, hints);
File file1 = new File(path, "名片.jpg");
MatrixToImageWriter.writeToFile(bitMatrix, "jpg", file1);
} catch (Exception e) {
e.printStackTrace();
}
}
}