zxing是一个开放源码的,用java实现的多种格式的1D/2D条码图像处理库,它包含了联系到其他语言的接口。可以实现使用手机的内置的摄像头完成条形码和二维码的扫描与解码。可以实现条形码和二维码的编码与解码。
github官网源码地址:https://github.com/zxing/zxing
开源库api文档:https://zxing.github.io/zxing/apidocs/
核心核心图像解码库和测试代码
java se javase-specific 客户机代码“条形码扫描器”
android android 客户条形码扫描器
androidtest 安卓测试应用,zx测试
android-integration 支持集成通过意图与条形码扫描器
androidtest android-core android-related 代码之间共享安卓,玻璃玻璃简单的谷歌眼镜的应用程序
zxingorg zxing.org 源码
zxing.appspot.com 基于web的条形码生成器在zxing.appspot.com背后的来源
ZXing-based第三方开源项目
qzxing 端口Qt框架
zxing-cpp 接口c++(分叉的弃用官方c++端口)
zxing_cpp rb绑定Ruby(不仅仅是JRuby),由zxing-cpp
python-zxing Python框架
zx 网络端口。NET和c#,和相关的Windows平台
PHP php-qrcode-detector-decoder港口
public void encode(String contents) { int WIDTH = 300, HEIGHT = 300 ; MultiFormatWriter formatWriter = new MultiFormatWriter(); try { // 按照指定的宽度,高度和附加参数对字符串进行编码 BitMatrix bitMatrix = formatWriter.encode(contents, BarcodeFormat.QR_CODE, WIDTH, HEIGHT/*, hints*/); Bitmap bitmap=StringUtil.bitMatrix2Bitmap(bitMatrix); Intent intent = new Intent(this, SurveyPointShowQrCodeActivity.class); ByteArrayOutputStream bOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, bOutputStream); byte[] bytes = bOutputStream.toByteArray(); intent.putExtra("bitmap", bytes); startActivity(intent); } catch (WriterException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
private Bitmap bitMatrix2Bitmap(BitMatrix matrix) { int w = matrix.getWidth(); int h = matrix.getHeight(); int[] rawData = new int[w * h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { int color = Color.WHITE; if (matrix.get(i, j)) { color = Color.BLACK; } rawData[i + (j * w)] = color; } } Bitmap bitmap = Bitmap.createBitmap(w, h, Config.RGB_565); bitmap.setPixels(rawData, 0, w, 0, 0, w, h); return bitmap; }
/** * 处理扫描结果 * @param result * @param barcode */ public void handleDecode(Result result, Bitmap barcode) { inactivityTimer.onActivity(); playBeepSoundAndVibrate(); String resultString = result.getText(); if (resultString.equals("")) { Toast.makeText(MipcaActivityCapture.this, "Scan failed!", Toast.LENGTH_SHORT).show(); }else { Intent resultIntent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("result", resultString); bundle.putParcelable("bitmap", barcode); resultIntent.putExtras(bundle); this.setResult(RESULT_OK, resultIntent); } MipcaActivityCapture.this.finish(); }
github官网源码地址:https://github.com/zxing/zxing