Softek Barcode Reader Toolkit 在Android平台上使用ScanBarCodeFromRGBABitmap

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进行处理,非常感谢!

上一篇 2021年10月26日
下一篇 2021年10月26日

相关推荐

发表回复

登录后才能评论