com.google.zxing.BarcodeFormat Java Examples
The following examples show how to use
com.google.zxing.BarcodeFormat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QRCodeGenerator.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 9 votes |
public static Bitmap transform(byte[] inputData) { String encoded; encoded = Base64.encodeToString(inputData, Base64.DEFAULT); MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); Bitmap bitmap = null; try { BitMatrix bitMatrix = multiFormatWriter.encode(encoded, BarcodeFormat.QR_CODE, 1000, 1000); BarcodeEncoder barcodeEncoder = new BarcodeEncoder(); bitmap = barcodeEncoder.createBitmap(bitMatrix); } catch (WriterException e) { Timber.e(e); } return bitmap; }
Example #2
Source File: UPCEANExtension5Support.java From ScreenCapture with MIT License | 6 votes |
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException { StringBuilder result = decodeRowStringBuffer; result.setLength(0); int end = decodeMiddle(row, extensionStartRange, result); String resultString = result.toString(); Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString); Result extensionResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber), new ResultPoint(end, rowNumber), }, BarcodeFormat.UPC_EAN_EXTENSION); if (extensionData != null) { extensionResult.putAllMetadata(extensionData); } return extensionResult; }
Example #3
Source File: ActionCreateCode.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
/** *二维码实现 * @param msg /二维码包含的信息 * @param path /二维码存放路径 */ public static void getBarCode(String msg,String path){ try { File file=new File(path); OutputStream ous=new FileOutputStream(file); if(StringUtils.isEmpty(msg) || ous==null) return; String format = "png"; MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); Map<EncodeHintType,String> map =new HashMap<EncodeHintType, String>(); //设置编码 EncodeHintType类中可以设置MAX_SIZE, ERROR_CORRECTION,CHARACTER_SET,DATA_MATRIX_SHAPE,AZTEC_LAYERS等参数 map.put(EncodeHintType.CHARACTER_SET,"UTF-8"); map.put(EncodeHintType.MARGIN,"1"); //生成二维码 BitMatrix bitMatrix = new MultiFormatWriter().encode(msg, BarcodeFormat.QR_CODE,300,300,map); MatrixToImageWriter.writeToStream(bitMatrix,format,ous); }catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: PayUtil.java From springboot-pay-example with Apache License 2.0 | 6 votes |
/** * 根据url生成二位图片对象 * * @param codeUrl * @return * @throws WriterException */ public static BufferedImage getQRCodeImge(String codeUrl) throws WriterException { Map<EncodeHintType, Object> hints = new Hashtable(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); int width = 256; BitMatrix bitMatrix = (new MultiFormatWriter()).encode(codeUrl, BarcodeFormat.QR_CODE, width, width, hints); BufferedImage image = new BufferedImage(width, width, 1); for(int x = 0; x < width; ++x) { for(int y = 0; y < width; ++y) { image.setRGB(x, y, bitMatrix.get(x, y) ? -16777216 : -1); } } return image; }
Example #5
Source File: Utils.java From privacy-friendly-qr-scanner with GNU General Public License v3.0 | 6 votes |
public static Bitmap generateCode(String data, BarcodeFormat format, Map<EncodeHintType,?> hints) { try { MultiFormatWriter writer = new MultiFormatWriter(); BitMatrix result = writer.encode(data, format, 100, 100, hints); int width = result.getWidth(); int height = result.getHeight(); int[] pixels = new int[width * height]; // All are 0, or black, by default for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE; } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; } catch (WriterException e) { return null; } }
Example #6
Source File: QREncoder.java From Lunary-Ethereum-Wallet with GNU General Public License v3.0 | 6 votes |
private boolean encodeContents(String data, Bundle bundle, String type, String formatString) { // Default to QR_CODE if no format given. format = null; if (formatString != null) { try { format = BarcodeFormat.valueOf(formatString); } catch (IllegalArgumentException iae) { // Ignore it then } } if (format == null || format == BarcodeFormat.QR_CODE) { this.format = BarcodeFormat.QR_CODE; encodeQRCodeContents(data, bundle, type); } else if (data != null && data.length() > 0) { contents = data; displayContents = data; title = "Text"; } return contents != null && contents.length() > 0; }
Example #7
Source File: HistoryManager.java From android-apps with MIT License | 6 votes |
public List<HistoryItem> buildHistoryItems() { SQLiteOpenHelper helper = new DBHelper(activity); List<HistoryItem> items = new ArrayList<HistoryItem>(); SQLiteDatabase db = null; Cursor cursor = null; try { db = helper.getReadableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC"); while (cursor.moveToNext()) { String text = cursor.getString(0); String display = cursor.getString(1); String format = cursor.getString(2); long timestamp = cursor.getLong(3); String details = cursor.getString(4); Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp); items.add(new HistoryItem(result, display, details)); } } finally { close(cursor, db); } return items; }
Example #8
Source File: PMedia.java From PHONK with GNU General Public License v3.0 | 6 votes |
public Bitmap generateQRCode(String text) { Bitmap bmp = null; Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // H = 30% damage int size = 256; BitMatrix bitMatrix = null; try { bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, size, size, hintMap); int width = bitMatrix.getWidth(); bmp = Bitmap.createBitmap(width, width, Bitmap.Config.RGB_565); for (int x = 0; x < width; x++) { for (int y = 0; y < width; y++) { bmp.setPixel(y, x, bitMatrix.get(x, y) == true ? Color.BLACK : Color.WHITE); } } } catch (WriterException e) { e.printStackTrace(); } return bmp; }
Example #9
Source File: RSSExpandedReader.java From barcodescanner-lib-aar with MIT License | 6 votes |
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException, FormatException { BitArray binary = BitArrayBuilder.buildBitArray(pairs); AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary); String resultingString = decoder.parseInformation(); ResultPoint[] firstPoints = pairs.get(0).getFinderPattern().getResultPoints(); ResultPoint[] lastPoints = pairs.get(pairs.size() - 1).getFinderPattern().getResultPoints(); return new Result( resultingString, null, new ResultPoint[]{firstPoints[0], firstPoints[1], lastPoints[0], lastPoints[1]}, BarcodeFormat.RSS_EXPANDED ); }
Example #10
Source File: QrCodeCreateUtil.java From java-study with Apache License 2.0 | 6 votes |
/** * 生成包含字符串信息的二维码图片 * * @param outputStream 文件输出流路径 * @param content 二维码携带信息 * @param qrCodeSize 二维码图片大小 * @param imageFormat 二维码的格式 * @throws WriterException * @throws IOException */ public static boolean createQrCode(OutputStream outputStream, String content, int qrCodeSize, String imageFormat) throws WriterException, IOException { //设置二维码纠错级别MAP Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); // 矫错级别 QRCodeWriter qrCodeWriter = new QRCodeWriter(); //创建比特矩阵(位矩阵)的QR码编码的字符串 BitMatrix byteMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, qrCodeSize, qrCodeSize, hintMap); // 使BufferedImage勾画QRCode (matrixWidth 是行二维码像素点) int matrixWidth = byteMatrix.getWidth(); BufferedImage image = new BufferedImage(matrixWidth - 200, matrixWidth - 200, BufferedImage.TYPE_INT_RGB); image.createGraphics(); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(0, 0, matrixWidth, matrixWidth); // 使用比特矩阵画并保存图像 graphics.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 - 100, j - 100, 1, 1); } } } return ImageIO.write(image, imageFormat, outputStream); }
Example #11
Source File: UPCEANExtension2Support.java From QrCodeScanner with GNU General Public License v3.0 | 6 votes |
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException { StringBuilder result = decodeRowStringBuffer; result.setLength(0); int end = decodeMiddle(row, extensionStartRange, result); String resultString = result.toString(); Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString); Result extensionResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber), new ResultPoint(end, rowNumber), }, BarcodeFormat.UPC_EAN_EXTENSION); if (extensionData != null) { extensionResult.putAllMetadata(extensionData); } return extensionResult; }
Example #12
Source File: HistoryManager.java From reacteu-app with MIT License | 6 votes |
public List<HistoryItem> buildHistoryItems() { SQLiteOpenHelper helper = new DBHelper(activity); List<HistoryItem> items = new ArrayList<HistoryItem>(); SQLiteDatabase db = null; Cursor cursor = null; try { db = helper.getReadableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC"); while (cursor.moveToNext()) { String text = cursor.getString(0); String display = cursor.getString(1); String format = cursor.getString(2); long timestamp = cursor.getLong(3); String details = cursor.getString(4); Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp); items.add(new HistoryItem(result, display, details)); } } finally { close(cursor, db); } return items; }
Example #13
Source File: ZxingUtils.java From wish-pay with Apache License 2.0 | 6 votes |
/** * 将内容contents生成长为width,宽为width的图片,返回刘文静 */ public static ServletOutputStream getQRCodeImge(String contents, int width, int height) throws IOException { ServletOutputStream stream = null; try { Map<EncodeHintType, Object> hints = Maps.newHashMap(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height, hints); MatrixToImageWriter.writeToStream(bitMatrix, "png", stream); return stream; } catch (Exception e) { log.error("create QR code error!", e); return null; } finally { if (stream != null) { stream.close(); } } }
Example #14
Source File: CaptureActivityHandler.java From AndroidHttpCapture with MIT License | 6 votes |
public CaptureActivityHandler(QrCodeScanActivity activity, Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType, ?> baseHints, String characterSet, CameraManager cameraManager) { this.activity = activity; decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet, new ViewfinderResultPointCallback(activity.getViewfinderView())); decodeThread.start(); state = State.SUCCESS; // Start ourselves capturing previews and decoding. this.cameraManager = cameraManager; cameraManager.startPreview(); restartPreviewAndDecode(); }
Example #15
Source File: MultiFormatUPCEANReader.java From ZXing-Orient with Apache License 2.0 | 6 votes |
public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) { @SuppressWarnings("unchecked") Collection<BarcodeFormat> possibleFormats = hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS); Collection<UPCEANReader> readers = new ArrayList<>(); if (possibleFormats != null) { if (possibleFormats.contains(BarcodeFormat.EAN_13)) { readers.add(new EAN13Reader()); } else if (possibleFormats.contains(BarcodeFormat.UPC_A)) { readers.add(new UPCAReader()); } if (possibleFormats.contains(BarcodeFormat.EAN_8)) { readers.add(new EAN8Reader()); } if (possibleFormats.contains(BarcodeFormat.UPC_E)) { readers.add(new UPCEReader()); } } if (readers.isEmpty()) { readers.add(new EAN13Reader()); // UPC-A is covered by EAN-13 readers.add(new EAN8Reader()); readers.add(new UPCEReader()); } this.readers = readers.toArray(new UPCEANReader[readers.size()]); }
Example #16
Source File: ReceiveActivity.java From smartcoins-wallet with MIT License | 6 votes |
Bitmap encodeAsBitmap(String str, String qrColor) throws WriterException { BitMatrix result; try { Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>(); hints.put(EncodeHintType.MARGIN, 0); result = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, qrimage.getWidth(), qrimage.getHeight(), hints); } catch (IllegalArgumentException iae) { // Unsupported format return null; } int w = qrimage.getWidth(); int h = qrimage.getHeight(); int[] pixels = new int[w * h]; for (int y = 0; y < h; y++) { int offset = y * (w); for (int x = 0; x < w; x++) { pixels[offset + x] = result.get(x, y) ? Color.parseColor(qrColor) : Color.WHITE; } } Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, w, 0, 0, w, h); return bitmap; }
Example #17
Source File: MultiFormatUPCEANReader.java From ScreenCapture with MIT License | 6 votes |
public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) { @SuppressWarnings("unchecked") Collection<BarcodeFormat> possibleFormats = hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS); Collection<UPCEANReader> readers = new ArrayList<>(); if (possibleFormats != null) { if (possibleFormats.contains(BarcodeFormat.EAN_13)) { readers.add(new EAN13Reader()); } else if (possibleFormats.contains(BarcodeFormat.UPC_A)) { readers.add(new UPCAReader()); } if (possibleFormats.contains(BarcodeFormat.EAN_8)) { readers.add(new EAN8Reader()); } if (possibleFormats.contains(BarcodeFormat.UPC_E)) { readers.add(new UPCEReader()); } } if (readers.isEmpty()) { readers.add(new EAN13Reader()); // UPC-A is covered by EAN-13 readers.add(new EAN8Reader()); readers.add(new UPCEReader()); } this.readers = readers.toArray(new UPCEANReader[readers.size()]); }
Example #18
Source File: EncodingHandler.java From Mobike with Apache License 2.0 | 6 votes |
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException { Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight); int width = matrix.getWidth(); int height = matrix.getHeight(); int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (matrix.get(x, y)) { pixels[y * width + x] = BLACK; } } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
Example #19
Source File: DecodeThread.java From iscanner_android with MIT License | 6 votes |
DecodeThread(MainActivity activity, Vector<BarcodeFormat> decodeFormats, String characterSet, ResultPointCallback resultPointCallback) { this.activity = activity; handlerInitLatch = new CountDownLatch(1); hints = new Hashtable<DecodeHintType, Object>(3); if (decodeFormats == null || decodeFormats.isEmpty()) { decodeFormats = new Vector<BarcodeFormat>(); decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS); decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); } hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); if (characterSet != null) { hints.put(DecodeHintType.CHARACTER_SET, characterSet); } hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); }
Example #20
Source File: HistoryManager.java From barcodescanner-lib-aar with MIT License | 6 votes |
public List<HistoryItem> buildHistoryItems() { SQLiteOpenHelper helper = new DBHelper(activity); List<HistoryItem> items = new ArrayList<>(); SQLiteDatabase db = null; Cursor cursor = null; try { db = helper.getReadableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC"); while (cursor.moveToNext()) { String text = cursor.getString(0); String display = cursor.getString(1); String format = cursor.getString(2); long timestamp = cursor.getLong(3); String details = cursor.getString(4); Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp); items.add(new HistoryItem(result, display, details)); } } finally { close(cursor, db); } return items; }
Example #21
Source File: DecodeThread.java From smart-farmer-android with Apache License 2.0 | 6 votes |
DecodeThread(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats, String characterSet, ResultPointCallback resultPointCallback) { this.activity = activity; handlerInitLatch = new CountDownLatch(1); hints = new Hashtable<DecodeHintType, Object>(3); if (decodeFormats == null || decodeFormats.isEmpty()) { decodeFormats = new Vector<BarcodeFormat>(); decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS); decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); } hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); if (characterSet != null) { hints.put(DecodeHintType.CHARACTER_SET, characterSet); } hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); }
Example #22
Source File: OneDimensionalCodeWriter.java From RipplePower with Apache License 2.0 | 6 votes |
/** * Encode the contents following specified format. {@code width} and * {@code height} are required size. This method may return bigger size * {@code BitMatrix} when specified size is too small. The user can set both * {@code width} and {@code height} to zero to get minimum size barcode. If * negative value is set to {@code width} or {@code height}, * {@code IllegalArgumentException} is thrown. */ @Override public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints) throws WriterException { if (contents.isEmpty()) { throw new IllegalArgumentException("Found empty contents"); } if (width < 0 || height < 0) { throw new IllegalArgumentException("Negative size is not allowed. Input: " + width + 'x' + height); } int sidesMargin = getDefaultMargin(); if (hints != null) { Integer sidesMarginInt = (Integer) hints.get(EncodeHintType.MARGIN); if (sidesMarginInt != null) { sidesMargin = sidesMarginInt; } } boolean[] code = encode(contents); return renderResult(code, width, height, sidesMargin); }
Example #23
Source File: PDF417Reader.java From barcodescanner-lib-aar with MIT License | 6 votes |
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) throws NotFoundException, FormatException, ChecksumException { List<Result> results = new ArrayList<>(); PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple); for (ResultPoint[] points : detectorResult.getPoints()) { DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5], points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points)); Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417); result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel()); PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther(); if (pdf417ResultMetadata != null) { result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata); } results.add(result); } return results.toArray(new Result[results.size()]); }
Example #24
Source File: UPCEANExtension2Support.java From weex with Apache License 2.0 | 6 votes |
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException { StringBuilder result = decodeRowStringBuffer; result.setLength(0); int end = decodeMiddle(row, extensionStartRange, result); String resultString = result.toString(); Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString); Result extensionResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber), new ResultPoint((float) end, (float) rowNumber), }, BarcodeFormat.UPC_EAN_EXTENSION); if (extensionData != null) { extensionResult.putAllMetadata(extensionData); } return extensionResult; }
Example #25
Source File: HistoryDetailsActivity.java From SecScanQR with GNU General Public License v3.0 | 6 votes |
/** * This method creates a picture of the scanned qr code */ private void showQrImage() { multiFormatWriter = new MultiFormatWriter(); Map<EncodeHintType, Object> hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class); hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hintMap.put(EncodeHintType.MARGIN, 1); /* default = 4 */ hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); try{ BarcodeFormat format = generalHandler.StringToBarcodeFormat(selectedFormat); BitMatrix bitMatrix = multiFormatWriter.encode(selectedCode, format, 250,250, hintMap); BarcodeEncoder barcodeEncoder = new BarcodeEncoder(); bitmap = barcodeEncoder.createBitmap(bitMatrix); codeImage.setImageBitmap(bitmap); } catch (Exception e){ codeImage.setVisibility(View.GONE); } }
Example #26
Source File: UPCAReader.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
private static Result maybeReturnResult(Result result) throws FormatException { String text = result.getText(); if (text.charAt(0) == '0') { return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A); } else { throw FormatException.getFormatInstance(); } }
Example #27
Source File: DecodeFormatManager.java From Viewer with Apache License 2.0 | 5 votes |
public static Set<BarcodeFormat> parseDecodeFormats(Intent intent) { Iterable<String> scanFormats = null; CharSequence scanFormatsString = intent.getStringExtra(Intents.Scan.FORMATS); if (scanFormatsString != null) { scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString)); } return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE)); }
Example #28
Source File: VINResultParser.java From ZXing-Orient with Apache License 2.0 | 5 votes |
@Override public VINParsedResult parse(Result result) { if (result.getBarcodeFormat() != BarcodeFormat.CODE_39) { return null; } String rawText = result.getText(); rawText = IOQ.matcher(rawText).replaceAll("").trim(); if (!AZ09.matcher(rawText).matches()) { return null; } try { if (!checkChecksum(rawText)) { return null; } String wmi = rawText.substring(0, 3); return new VINParsedResult(rawText, wmi, rawText.substring(3, 9), rawText.substring(9, 17), countryCode(wmi), rawText.substring(3, 8), modelYear(rawText.charAt(9)), rawText.charAt(10), rawText.substring(11)); } catch (IllegalArgumentException iae) { return null; } }
Example #29
Source File: QRPresenterActivity.java From Meshenger with GNU General Public License v3.0 | 5 votes |
private void generateQR() throws Exception { json = generateJson(); Log.d(QRPresenterActivity.class.getSimpleName(), json); MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); try { BitMatrix bitMatrix = multiFormatWriter.encode(json, BarcodeFormat.QR_CODE,1080,1080); BarcodeEncoder barcodeEncoder = new BarcodeEncoder(); Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix); ((ImageView) findViewById(R.id.QRView)).setImageBitmap(bitmap); } catch (WriterException e) { e.printStackTrace(); } }
Example #30
Source File: Code128Writer.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
@Override public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints) throws WriterException { if (format != BarcodeFormat.CODE_128) { throw new IllegalArgumentException("Can only encode CODE_128, but got " + format); } return super.encode(contents, format, width, height, hints); }