• PUDN用户
    了解作者
  • Java
    开发工具
  • 979KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2923
    下载次数
  • 2011-05-07 23:59
    上传日期
android上使用ZXing识别条形码和二维码,代码简单易懂,相信能帮助读者迅速掌握相关的开发
ZxingDemo.rar
内容介绍
/* * Copyright 2009 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.zxing.pdf417.decoder; import com.google.zxing.FormatException; import com.google.zxing.NotFoundException; import com.google.zxing.common.BitMatrix; /** * <p> * This class parses the BitMatrix image into codewords. * </p> * * @author SITA Lab (kevin.osullivan@sita.aero) */ final class BitMatrixParser { private static final int MAX_ROW_DIFFERENCE = 6; private static final int MAX_ROWS = 90; //private static final int MAX_COLUMNS = 30; // Maximum Codewords (Data + Error) private static final int MAX_CW_CAPACITY = 929; private static final int MODULES_IN_SYMBOL = 17; private final BitMatrix bitMatrix; private int rows = 0; //private int columns = 0; private int leftColumnECData = 0; private int rightColumnECData = 0; private int eraseCount = 0; private int[] erasures = null; private int ecLevel = -1; BitMatrixParser(BitMatrix bitMatrix) { this.bitMatrix = bitMatrix; } /** * To ensure separability of rows, codewords of consecutive rows belong to * different subsets of all possible codewords. This routine scans the * symbols in the barcode. When it finds a number of consecutive rows which * are the same, it assumes that this is a row of codewords and processes * them into a codeword array. * * @return an array of codewords. */ int[] readCodewords() throws FormatException { int width = bitMatrix.getWidth(); // TODO should be a rectangular matrix int height = width; erasures = new int[MAX_CW_CAPACITY]; // Get the number of pixels in a module across the X dimension //float moduleWidth = bitMatrix.getModuleWidth(); float moduleWidth = 1.0f; // Image has been sampled and reduced int[] rowCounters = new int[width]; int[] codewords = new int[MAX_CW_CAPACITY]; int next = 0; int matchingConsecutiveScans = 0; boolean rowInProgress = false; int rowNumber = 0; int rowHeight = 0; for (int i = 1; i < height; i++) { if (rowNumber >= MAX_ROWS) { // Something is wrong, since we have exceeded // the maximum rows in the specification. // TODO Maybe return error code return null; } int rowDifference = 0; // Scan a line of modules and check the // difference between this and the previous line for (int j = 0; j < width; j++) { // Accumulate differences between this line and the // previous line. if (bitMatrix.get(j, i) != bitMatrix.get(j, i - 1)) { rowDifference++; } } if (rowDifference <= moduleWidth * MAX_ROW_DIFFERENCE) { for (int j = 0; j < width; j++) { // Accumulate the black pixels on this line if (bitMatrix.get(j, i)) { rowCounters[j]++; } } // Increment the number of consecutive rows of pixels // that are more or less the same matchingConsecutiveScans++; // Height of a row is a multiple of the module size in pixels // Usually at least 3 times the module size if (matchingConsecutiveScans >= moduleWidth * 2) { // MGMG // We have some previous matches as well as a match here // Set processing a unique row. rowInProgress = true; } } else { if (rowInProgress) { // Process Row next = processRow(rowCounters, rowNumber, rowHeight, codewords, next); if (next == -1) { // Something is wrong, since we have exceeded // the maximum columns in the specification. // TODO Maybe return error code return null; } // Reinitialize the row counters. for (int j = 0; j < rowCounters.length; j++) { rowCounters[j] = 0; } rowNumber++; rowHeight = 0; } matchingConsecutiveScans = 0; rowInProgress = false; } rowHeight++; } // Check for a row that was in progress before we exited above. if (rowInProgress) { // Process Row if (rowNumber >= MAX_ROWS) { // Something is wrong, since we have exceeded // the maximum rows in the specification. // TODO Maybe return error code return null; } next = processRow(rowCounters, rowNumber, rowHeight, codewords, next); rowNumber++; rows = rowNumber; } erasures = trimArray(erasures, eraseCount); return trimArray(codewords, next); } /** * Trim the array to the required size. * * @param array the array * @param size the size to trim it to * @return the new trimmed array */ private static int[] trimArray(int[] array, int size) { if (size > 0) { int[] a = new int[size]; for (int i = 0; i < size; i++) { a[i] = array[i]; } return a; } else { return null; } } /** * Convert the symbols in the row to codewords. * Each PDF417 symbol character consists of four bar elements and four space * elements, each of which can be one to six modules wide. The four bar and * four space elements shall measure 17 modules in total. * * @param rowCounters an array containing the counts of black pixels for each column * in the row. * @param rowNumber the current row number of codewords. * @param rowHeight the height of this row in pixels. * @param codewords the codeword array to save codewords into. * @param next the next available index into the codewords array. * @return the next available index into the codeword array after processing * this row. */ int processRow(int[] rowCounters, int rowNumber, int rowHeight, int[] codewords, int next) throws FormatException { int width = bitMatrix.getWidth(); int columnNumber = 0; long symbol = 0; for (int i = 0; i < width; i += MODULES_IN_SYMBOL) { // This happens in real life and is almost surely a rare misdecode if (i + MODULES_IN_SYMBOL > rowCounters.length) { throw FormatException.getFormatInstance(); } for (int mask = MODULES_IN_SYMBOL - 1; mask >= 0; mask--) { if (rowCounters[i + (MODULES_IN_SYMBOL - 1 - mask)] >= rowHeight >>> 1) { symbol |= 1L << mask; } } if (columnNumber > 0) { int cw = getCodeword(symbol); // if (debug) System.out.println(" " + Long.toBinaryString(symbol) + // " cw=" +cw + " ColumnNumber=" +columnNumber + "i=" +i); if (cw < 0 && i < width - MODULES_IN_SYMBOL) { // Skip errors on the Right row indicator column erasures[eraseCount] = next; next++; eraseCount++; } else { codewords[next++] = cw; } } else { // Left row indicator column int cw = getCodeword(symbol); // if (debug) System.out.println(" " + Long.toBinaryString(symbol) + // " cw=" +cw + " ColumnNumber=" +columnNumber + "i=" +i); if (ecLevel < 0) { switch (rowNumber % 3) { case 0: break; case 1: leftColumnE
评论
    相关推荐
    • rokon_demo.zip
      使用Rokon开发的一个供学习用的Demo。很多同学都反映使用物理引擎后的Sprite无法进行控制。通过这个Demo告诉大家对采用物理引擎的Sprite进行控制的简单方法。 ·从屏幕左边射出不同速度、不同角度的、不同色彩的球 ...
    • Rokon.zip
      基于Android开发的小游戏,适合初学者
    • AndroidDemo.rar
      众多Android+开源项目推荐,给力工作给力学习.pdf
    • rokon.rar
      rokon_src_2-0-3_游戏引擎,Java环境下的游戏引擎,同时也适用于Android手机游戏开发,里面的一些引擎可以直接调用,省去你重新编写的麻烦
    • Rokon例子1-5压缩包
      整理出来的Android 游戏引擎Rokon的几个范例,简单易懂,适合入门
    • android连连看游戏代码
      rokon游戏引擎做的android连连看游戏代码
    • rokon:从 code.google.comprokon 自动导出
      罗康 适用于 Android 的旧 OpenGL ES 1.1 图形/游戏引擎。 2009 年中期至 2010 年中期开发。 目前大多不相关; 为了历史,从谷歌代码迁移。
    • Rokon游戏引擎
      Rokon 游戏引擎源码,可编译,游戏开发的可以研究
    • android 游戏引擎Rokon实例教程
      android 游戏引擎Rokon实例教程
    • rokon android游戏引擎源代码
      rokon android游戏引擎源代码,2D的,不管是对游戏编程,还是引擎编写,引用的价值要远远高于本身