论坛首页 移动开发技术论坛

QR code类库

浏览 9089 次
锁定老帖子 主题:QR code类库
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-06-03   最后修改:2010-06-04
Google code发现的好东西。


QR code 类库: http://code.google.com/p/zxing/




ZXing (pronounced "zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java. Our focus is on using the built-in camera on mobile phones to photograph and decode barcodes on the device, without communicating with a server. We currently have support for:



UPC-A and UPC-E

EAN-8 and EAN-13

Code 39

Code 93

Code 128

QR Code

ITF

Codabar

RSS-14 (all variants)

Data Matrix ('alpha' quality)

PDF 417 ('alpha' quality)

This library is divided into several components; some are actively supported:



core: The core image decoding library, and test code

javase: J2SE-specific client code

android: Android client, called Barcode Scanner

androidtest: Android test app

android-integration: Supports integration with our Barcode Scanner app via Intent

zxingorg: The source behind zxing.org/w

zxing.appspot.com: The source behind our web-based barcode generator

Some modules are contributed and/or intermittently maintained:



javame: JavaME client

csharp: Partial C# port

cpp: Partial C++ port

rim: RIM/Blackberry-specific client build

iphone: iPhone client + port to Objective C / C++ (QR code only)

bug: Client for BugLabs's BUG

jruby: Ruby wrapper

actionscript: partial port to Actionscript




To complement our decoding software, we have created a web-based QR Code generator which supports contact information, calendar events, URLs, and much more.
   发表时间:2010-06-04  
毕业设计刚搞的就是QRCODE,这个项目帮了不少忙
0 请登录后投票
   发表时间:2010-06-07  
贝壳水母 写道
毕业设计刚搞的就是QRCODE,这个项目帮了不少忙

此类库做条形码扫描有很大的帮助。
0 请登录后投票
   发表时间:2010-06-11  
能详细讲一下怎么使用这个开源项目嘛!
0 请登录后投票
   发表时间:2010-06-11   最后修改:2010-06-11
有个地方需要注意下,直接调用该项目的QR码自动生成方法
(如:
QRCodeWriter_ED qrwriter = new QRCodeWriter_ED();
ByteMatrix matrix = qrwriter.encode("source", BarcodeFormat.QR_CODE, 200, 200,hints);MatrixToImageWriter.writeToFile(matrix, "png", file);

)
时,生成的图像是黑白颠倒的,以下是我改动后的QRCodeWriter类,修改后图像正常了
不知道各位有没有遇过这个问题,具体缘由以及是否会对其他方法有影响我不清楚,请指教

/*     */ package com.google.zxing.qrcode;
/*     */ 
/*     */ import com.google.zxing.BarcodeFormat;
/*     */ import com.google.zxing.EncodeHintType;
/*     */ import com.google.zxing.Writer;
/*     */ import com.google.zxing.WriterException;
/*     */ import com.google.zxing.common.ByteMatrix;
/*     */ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
/*     */ import com.google.zxing.qrcode.encoder.Encoder;
/*     */ import com.google.zxing.qrcode.encoder.QRCode;
/*     */ import java.util.Hashtable;
/*     */ 
/*     */ public final class QRCodeWriter_ED
/*     */   implements Writer
/*     */ {
/*     */   private static final int QUIET_ZONE_SIZE = 4;
/*     */ 
/*     */   public ByteMatrix encode(String contents, BarcodeFormat format, int width, int height)
/*     */     throws WriterException
/*     */   {
/*  42 */     return encode(contents, format, width, height, null);
/*     */   }
/*     */ 
/*     */   public ByteMatrix encode(String contents, BarcodeFormat format, int width, int height, Hashtable hints)
/*     */     throws WriterException
/*     */   {
/*  48 */     if ((contents == null) || (contents.length() == 0)) {
/*  49 */       throw new IllegalArgumentException("Found empty contents");
/*     */     }
/*     */ 
/*  52 */     if (format != BarcodeFormat.QR_CODE) {
/*  53 */       throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
/*     */     }
/*     */ 
/*  56 */     if ((width < 0) || (height < 0)) {
/*  57 */       throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' + height);
/*     */     }
/*     */ 
/*  61 */     ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
/*  62 */     if (hints != null) {
/*  63 */       ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel)hints.get(EncodeHintType.ERROR_CORRECTION);
/*  64 */       if (requestedECLevel != null) {
/*  65 */         errorCorrectionLevel = requestedECLevel;
/*     */       }
/*     */     }
/*     */ 
/*  69 */     QRCode code = new QRCode();
/*  70 */     Encoder.encode(contents, errorCorrectionLevel, hints, code);
/*  71 */     return renderResult(code, width, height);
/*     */   }
/*     */ 
/*     */   private static ByteMatrix renderResult(QRCode code, int width, int height)
/*     */   {
/*  77 */     ByteMatrix input = code.getMatrix();
/*  78 */     int inputWidth = input.getWidth();
/*  79 */     int inputHeight = input.getHeight();
/*  80 */     int qrWidth = inputWidth + 8;
/*  81 */     int qrHeight = inputHeight + 8;
/*  82 */     int outputWidth = Math.max(width, qrWidth);
/*  83 */     int outputHeight = Math.max(height, qrHeight);
/*     */ 
/*  85 */     int multiple = Math.min(outputWidth / qrWidth, outputHeight / qrHeight);
/*     */ 
/*  90 */     int leftPadding = (outputWidth - (inputWidth * multiple)) / 2;
/*  91 */     int topPadding = (outputHeight - (inputHeight * multiple)) / 2;
/*     */ 
/*  93 */     ByteMatrix output = new ByteMatrix(outputWidth, outputHeight);
/*  94 */     byte[][] outputArray = output.getArray();
/*     */ 
/*  98 */     byte[] row = new byte[outputWidth];
/*     */ 
/* 101 */     for (int y = 0; y < topPadding; ++y) {
//下面一行代码原为setRowColor(outputArray[y], -1);
/* 102 */       setRowColor(outputArray[y], 0);
/*     */     }
/*     */ 
/* 106 */     byte[][] inputArray = input.getArray();
/* 107 */     for (int y = 0; y < inputHeight; ++y)
/*     */     {
/* 109 */       for (int x = 0; x < leftPadding; ++x) {
//原为row[x] = -1;
/* 110 */         row[x] = 0;
/*     */       }
/*     */ 
/* 114 */       int offset = leftPadding;
/* 115 */       for (int x = 0; x < inputWidth; ++x) {
//原为byte value = (inputArray[y][x] == 1) ? 0 : -1;
/* 116 */         byte value = (inputArray[y][x] == 1) ? -1 : 0;
/* 117 */         for (int z = 0; z < multiple; ++z) {
/* 118 */           row[(offset + z)] = value;
/*     */         }
/* 120 */         offset += multiple;
/*     */       }
/*     */ 
/* 124 */       offset = leftPadding + inputWidth * multiple;
/* 125 */       for (int x = offset; x < outputWidth; ++x) {
//原为row[x] = -1;
/* 126 */         row[x] = 0;
/*     */       }
/*     */ 
/* 130 */       offset = topPadding + y * multiple;
/* 131 */       for (int z = 0; z < multiple; ++z) {
/* 132 */         System.arraycopy(row, 0, outputArray[(offset + z)], 0, outputWidth);
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 137 */     int offset = topPadding + inputHeight * multiple;
/* 138 */     for (int y = offset; y < outputHeight; ++y) {
/* 139 */       setRowColor(outputArray[y], 0);
/*     */     }
/*     */ 
/* 142 */     return output;
/*     */   }
/*     */ 
/*     */   private static void setRowColor(byte[] row, byte value) {
/* 146 */     for (int x = 0; x < row.length; ++x)
/* 147 */       row[x] = value;
/*     */   }
/*     */ }
0 请登录后投票
论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics