zxing 这个是google的 
下载地址 
http://code.google.com/p/zxing/downloads/list

二维码源码案例

package com.utils;

import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Hashtable; import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix; public class UtilsQrCode { private static final int BLACK = 0xff000000;
private static final int WHITE = 0xFFFFFFFF; /**
* @param args
*/
public static void main(String[] args) {
File file = new File("C:\\Users\\huage\\Desktop\\图片\\"+new Date().getTime()+".png");
encode("http://www.baidu.com", file, BarcodeFormat.QR_CODE, 200, 200);
} /**
* @param contents
* @param file
* @param format
* @param width
* @param height
*/
public static void encode(String contents, File file, BarcodeFormat format, int width, int height) {
try {
contents = new String(contents.getBytes("UTF-8"), "ISO-8859-1");
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, format, width, height,hints);
BufferedImage image = toBufferedImage(bitMatrix);
writeToFile(image, "png", file);
} catch (Exception e) {
e.printStackTrace();
}
} public static byte[] imgToBytes(BufferedImage image){
if( image == null ) return new byte[0];
byte[] data = ((DataBufferByte) image.getData().getDataBuffer()).getData();
return data;
} public static void writeToFile(BufferedImage image, String format, File file) throws IOException {
if( image == null || file == null ) return;
ImageIO.write(image, format, file);
} public static BufferedImage toBufferedImage(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, matrix.get(x, y) == true ? BLACK : WHITE);
}
}
return image;
} }

java-二维码编写zxing的更多相关文章

  1. java二维码生成-谷歌(Google.zxing)开源二维码生成学习及实例

    java二维码生成-谷歌(Google.zxing)开源二维码生成的实例及介绍   我们使用比特矩阵(位矩阵)的QR码编码在缓冲图片上画出二维码 实例有以下一个传入参数 OutputStream ou ...

  2. Atitit java 二维码识别 图片识别

    Atitit java 二维码识别 图片识别 1.1. 解码11.2. 首先,我们先说一下二维码一共有40个尺寸.官方叫版本Version.11.3. 二维码的样例:21.4. 定位图案21.5. 数 ...

  3. Java二维码生成与解码

      基于google zxing 的Java二维码生成与解码   一.添加Maven依赖(解码时需要上传二维码图片,所以需要依赖文件上传包) <!-- google二维码工具 --> &l ...

  4. Java二维码生成与解码工具Zxing使用

    Zxing是Google研发的一款非常好用的开放源代码的二维码生成工具,目前源码托管在github上,源码地址: https://github.com/zxing/zxing 可以看到Zxing库有很 ...

  5. Java生成带小图标的二维码-google zxing 工具类

    近期一直忙于开发微信商城项目,应客户要求,要开发个有图标的二维码.经过两次改版,终于实现了该功能(第一次没有小图标,这次才整合好的),如下是完整代码 . 该代码使用Java7开发,另外使用 core- ...

  6. java二维码之利用谷歌的zxing生成二维码,解析二维码

    生成二维码 @RequestMapping("/123") public void test(HttpServletRequest request,HttpServletRespo ...

  7. java二维码小试牛刀

    旁白: 由于工作需要,要做一个java的二维码的图片,花了2天的时间学习了一下,过程中也遇到了一些问题,这里做个笔记,收藏了. 废话不多说了,入题吧! 转自:http://www.open-open. ...

  8. Java二维码登录流程实现(包含短地址生成,含部分代码)

    近年来,二维码的使用越来越风生水起,笔者最近手头也遇到了一个需要使用二维码扫码登录网站的活,所以研究了一下这一套机制,并用代码实现了整个流程,接下来就和大家聊聊二维码登录及的那些事儿. 二维码原理 二 ...

  9. java二维码开发

    之前就写过很多关于二维码的东西,一直没有时间整理一下,所以呢今天就先来介绍一下如何利用java开发二维码.生成二维码有很多jar包可以实现,例如Zxing,QRcode,前者是谷歌的,后者日本的,这里 ...

随机推荐

  1. Android开发书籍推荐:从入门到精通系列学习路线书籍介绍

    Android开发书籍推荐:从入门到精通系列学习路线书籍介绍 很多时候我们都会不断收到新手的提问"Android开发的经典入门教材和学习路线?"."Android 开发入 ...

  2. background-origin 设置背景图片原始起始位置

  3. asp.net webapi [FromBody]string 获取不到ajax post的数据的解决方法

    webapi中如下([FromBody]string jsonData: public async Task<ResItem> Post([FromBody]string jsonData ...

  4. 修复ext4日志(jbd2)bug( Ext4 文件系统有以下 Bug)

    from:http://blog.donghao.org/2013/03/20/%E4%BF%AE%E5%A4%8Dext4%E6%97%A5%E5%BF%97%EF%BC%88jbd2%EF%BC% ...

  5. android edittext 去边框 去下划线

    EditText的background属性设置为@null就搞定了:android:background="@null"style属性倒是可加可不加 附原文:@SlumberMac ...

  6. S2总结笔记

    第一章:深入.NET框架 1..NET FrameWork两大组件是什么? 解析:.NET 框架类库(FCL:FrameWork Class Library)和公共语言运行时(CLR:common l ...

  7. AAL template: ROI to brain lobe

    Reference: Altmann A, Schröter M S, Spoormaker V I, et al. Validation of non-REM sleep stage decodin ...

  8. web standards

    http://www.w3.org/standards/ http://www.webstandards.org/learn/faq/#p213 http://www.w3.org/standards ...

  9. C#/JS 获取二维数组组合

    C#获取二维数组组合 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  10. 前端见微知著JavaScript基础篇:this or that ?

    上节,我们提到了this关键字的问题,并且追加了一句很有意义的话:谁调用我,我指向谁.的确,在javascript中,在默认情况下,this会指向一个已经初始化的window对象.所以你不论有多少全局 ...