`

Quick Response

    博客分类:
  • Java
 
阅读更多

http://javapapers.com/core-java/java-qr-code/

 

<dependency>
	<groupId>com.google.zxing</groupId>
	<artifactId>core</artifactId>
	<version>2.2</version>
</dependency>

<dependency>
	<groupId>com.google.zxing</groupId>
	<artifactId>javase</artifactId>
	<version>2.2</version>
</dependency>

 

 

无图片的二维码

package org.quickresponse;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

public class QRCodeSimple {

	public static void main(String[] args) throws WriterException, IOException,
			NotFoundException {
		String qrCodeData = "https://www.gconline.cn/sis/public/pdf/clause/JJJ.pdf";
		String filePath = "QRCode.png";
		String charset = "UTF-8"; // or "ISO-8859-1"
		Map hintMap = new HashMap();
		hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

		createQRCode(qrCodeData, filePath, charset, hintMap, 200, 200);
		System.out.println("QR Code image created successfully!");

		System.out.println("Data read from QR Code: "
				+ readQRCode(filePath, charset, hintMap));

	}

	public static void createQRCode(String qrCodeData, String filePath,
			String charset, Map hintMap, int qrCodeheight, int qrCodewidth)
			throws WriterException, IOException {
		BitMatrix matrix = new MultiFormatWriter().encode(
				new String(qrCodeData.getBytes(charset), charset),
				BarcodeFormat.QR_CODE, qrCodewidth, qrCodeheight, hintMap);
		MatrixToImageWriter.writeToFile(matrix, filePath.substring(filePath
				.lastIndexOf('.') + 1), new File(filePath));
	}

	public static String readQRCode(String filePath, String charset, Map hintMap)
			throws FileNotFoundException, IOException, NotFoundException {
		BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
				new BufferedImageLuminanceSource(
						ImageIO.read(new FileInputStream(filePath)))));
		Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap,
				hintMap);
		return qrCodeResult.getText();
	}
}
 

 

分享到:
评论

相关推荐

    使用C#生成QR码(学名为快速响应矩阵码;Quick Response Code) 可输入文字 也可输入图片

    使用C#生成QR码(学名为快速响应矩阵码;Quick Response Code) 可输入文字 也可输入图片

    Multiple-image encryption based on angular-multiplexing holography with quick response code and spiral phase keys

    Multiple-image encryption based on angular-multiplexing holography with quick response code and spiral phase keys

    ThoughtWorks.QRCode功能强劲的生成二维码的动态链接库

    二维码是用某种特定的几何图形按一定规律在平面分布的、黑白相间的、记录数据符号信息的...ThoughtWorks.QRCode是一款功能强劲的动态链接库,能够为.net应用生成二维码,QR 全称为 Quick Response,是一种编码方式。

    Python二维码生成库qrcode安装和使用示例

    二维码简称 QR Code(Quick Response Code),学名为快速响应矩阵码,是二维条码的一种,由日本的 Denso Wave 公司于 1994 年发明。现随着智能手机的普及,已广泛应用于平常生活中,例如商品信息查询、社交好友互动...

    Android代码-DialogUtil

    any problem or bug, join the qq group to get a quick response: important points if you do not invoke setActivity(activit), please invoke show() after in or after the activity onResume,or it may ...

    二维码活码管理系统 v 2.0 (响应式网站整套编码)

    二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型. 重点技术 1.使用插件绘制二维码 ...

    RT3602AC-01.pdf

    response trigger level. Besides, the setting function also supposes this two rails address exchange. The RT3602AC provides VR ready output signals. It also features complete fault protection ...

    最新二维码生成工具大小、颜色可调

    日本最新的二维码生成工具,单文件绿色版,QR码是二维条码的一种,QR来自英文“Quick Response”的缩写,即快速反应的意思,源自发明者希望QR码可让其内容快速被解码。QR码比普通条码可储存更多资料,亦无需像普通...

    二维码活码管理系统源码.zip

    二维码又称二维条码,常见的二维码为QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型. 二维码生成后,二维码图案不变,...

    QRConde.zip

    二维码(Quick Response Code),又称二维条码,它是用特定的几何图形按一定规律在平面(二维方向)上分布的黑白相间的图形,是所有信息数据的一把钥匙。在现代商业活动中,可实现的应用十分广泛,如:产品防伪/溯源...

    芝浦伺服驱动器说明书BS_Servo_Amplifiers_X_e.pdf

    The X series BS servo amplifier has further improved the quick response and high accuracy of the predecessor amplifier by employing a new high-speed calculation system. A variety of functions and ...

    基于CVT的混联式电动汽车动力切换平稳性研究-基于CVT的混联式电动汽车动力切换平稳性研究.rar

    基于CVT的混联式电动汽车动力切换平稳性研究-基于CVT的混联式电动汽车动力切换平稳性研究.rar ...quick response to acceleration command and smooth drive mode switching without strange feeling of driver

    条形码C#实现操作帮助类

    5. QR码(Quick Response Code):以方块和黑白二维图案组成,可以存储较大数量和种类的数据。 生成条形码可以使用编程语言中的相应库来实现,比如Python中的`barcode`库或者`pyzbar`库。通过这些库,你可以根据所...

    论文研究-突发事件下基于贝叶斯更新的延迟生产策略.pdf

    论文研究-突发事件下基于贝叶斯更新的延迟生产策略.pdf, 基于突发事件对多区域影响的不确定性导致应急物资生产策略和产量的决策困难,研究供应商如何选择生产策略进行...

    pb生成二维码

    QR码是二维条码的一种,QR 来自英文 “Quick Response” 的缩写,即快速反应的意思,源自发明者希望 QR 码可让其内容快速被解码。QR码比普通条码可储存更多资料,亦无需像普通条码般在扫描时需直线对准扫描器。 QR ...

    Pro Android 4

    This is our fourth edition on the subject of Android, and it’s our best edition yet. Pro Android 4 is an extensive programming guide for the Android ...we are only an e-mail away for a quick response.

    Cloud-fog-dew architecture

    With cloud computing, we can have high availability and affordability but it may not offer quick response due to its considerable round trip time. Fog computing gives huge advantage on latency side, ...

    Xceed.Ultimate.Suite.v10.4.10458.Incl.Keygen-Lz0.part4

    Our team's quick response time with help and solutions earns them praise from customers on a daily basis. Also available is the Blueprint Edition so you can also get the fully commented C# source ...

    Xceed.Ultimate.Suite.v10.4.10458.Incl.Keygen-Lz0.part5

    Our team's quick response time with help and solutions earns them praise from customers on a daily basis. Also available is the Blueprint Edition so you can also get the fully commented C# source ...

    Xceed.Ultimate.Suite.v10.4.10458.Incl.Keygen-Lz0.part3

    Our team's quick response time with help and solutions earns them praise from customers on a daily basis. Also available is the Blueprint Edition so you can also get the fully commented C# source ...

Global site tag (gtag.js) - Google Analytics