Android版本的SDK不能直接从图像文件中读取,但它可以使用类似于以下的代码从位图中读取。
Barcode barcode = new Barcode();// Load your image file into a bitmapint width = bitmap.getWidth();int height = bitmap.getHeight();byte[] rawBytes = new byte[width * height * 4];int index = 0;for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int colour = bitmap.getPixel(x, y); int red = (colour >> 16) & 0xff; int green = (colour >> 8) & 0xff; int blue = colour & 0xff; int alpha = 0; int rawIndex = index * 4 rawBytes[rawIndex++] = (byte) red ; rawBytes[rawIndex++] = (byte) green; rawBytes[rawIndex++] = (byte) blue; rawBytes[rawIndex++] = (byte) alpha; index++; }}int n = barcode.ScanBarCodeFromRGBABitmap(bitmap.getWidth(), bitmap.getHeight(), rawBytes);if (n > 0) strBarcode = barcode.GetBarString(1);
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!