建站行业现状探讨,学校官方网站的建设目标是什么,油烟机seo关键词,海洋cms怎么做电影网站qr码生成如果您精通技术和小工具#xff0c;则必须了解QR码。 这些天#xff0c;到处都可以找到它-在博客#xff0c;网站#xff0c;甚至在某些公共场所。 这在移动应用程序中非常流行#xff0c;在移动应用程序中#xff0c;您可以使用QR Code扫描仪应用程序扫描QR Cod… qr码生成 如果您精通技术和小工具则必须了解QR码。 这些天到处都可以找到它-在博客网站甚至在某些公共场所。 这在移动应用程序中非常流行在移动应用程序中您可以使用QR Code扫描仪应用程序扫描QR Code它将显示文本或将您重定向到网页如果是URL。 我最近遇到了这个问题发现它非常有趣。 如果您想了解QR Code可以在Wikipedia QR Code页面上找到很多有用的信息。当我在许多网站中找到此类图像时我便开始寻找如何使用Java Code生成图像的信息。 我研究了一些在市场上可以作为开源使用的API发现zxing是最简单和最好的用法。 这是您可以用来通过zxing API创建QR Code图片的程序。 package com.adly.generator;import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;import javax.imageio.ImageIO;import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;public class GenerateQRCode {/*** param args* throws WriterException* throws IOException*/public static void main(String[] args) throws WriterException, IOException {String qrCodeText http://www.journaldev.com;String filePath D:\\Pankaj\\JD.png;int size 125;String fileType png;File qrFile new File(filePath);createQRImage(qrFile, qrCodeText, size, fileType);System.out.println(DONE);}private static void createQRImage(File qrFile, String qrCodeText, int size,String fileType) throws WriterException, IOException {// Create the ByteMatrix for the QR-Code that encodes the given StringHashtable hintMap new Hashtable();hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);QRCodeWriter qrCodeWriter new QRCodeWriter();BitMatrix byteMatrix qrCodeWriter.encode(qrCodeText,BarcodeFormat.QR_CODE, size, size, hintMap);// Make the BufferedImage that are to hold the QRCodeint matrixWidth byteMatrix.getWidth();BufferedImage image new BufferedImage(matrixWidth, matrixWidth,BufferedImage.TYPE_INT_RGB);image.createGraphics();Graphics2D graphics (Graphics2D) image.getGraphics();graphics.setColor(Color.WHITE);graphics.fillRect(0, 0, matrixWidth, matrixWidth);// Paint and save the image using the ByteMatrixgraphics.setColor(Color.BLACK);for (int i 0; i matrixWidth; i) {for (int j 0; j matrixWidth; j) {if (byteMatrix.get(i, j)) {graphics.fillRect(i, j, 1, 1);}}}ImageIO.write(image, fileType, qrFile);}} 这是此程序创建的QR Code图像文件。 您可以使用移动QR码扫描仪应用程序对其进行测试。 它应该指向JournalDev主页URL。 如果您没有移动应用程序进行测试请不要担心。 您也可以通过命令行使用zxing API对其进行测试。 我在Windows操作系统上这是对其进行测试的命令。 如果您使用的是Unix / Linux / Mac OS请相应地进行更改。 D:\Pankaj\zxingjava -cp javase\javase.jar;core\core.jar com.google.zxing.client.j2se.CommandLineRunner D:\Pankaj\JD.png
file:/D:/Pankaj/JD.png (format: QR_CODE, type: URI):
Raw result:http://www.journaldev.comParsed result:http://www.journaldev.comFound 4 result points.Point 0: (35.5,89.5)Point 1: (35.5,35.5)Point 2: (89.5,35.5)Point 3: (80.5,80.5) 动态QR码生成提示 如果要动态生成QR码则可以使用Google Charts Tools进行。 对于上述情况URL为https://chart.googleapis.com/chartchs125×125chtqrchlhttp://www.journaldev.com 祝您编程愉快别忘了分享 参考在Developer Recipes博客上从我们的JCG合作伙伴 Pankaj Kumar 从Java程序生成QR Code图像 。 翻译自: https://www.javacodegeeks.com/2012/10/generate-qr-code-image-from-java-program.htmlqr码生成