Closed JakeWang123 closed 7 years ago
1.布局如下 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/fragmentContainer" android:layout_width="match_parent" android:layout_height="match_parent"
> <cn.bingoogolapple.qrcode.zxing.ZXingView android:id="@+id/zxingview" android:layout_width="match_parent" android:layout_height="match_parent" app:qrcv_animTime="1000" app:qrcv_barCodeTipText="将条码放入框内,即可自动扫描" app:qrcv_barcodeRectHeight="140dp" app:qrcv_borderColor="@android:color/white" app:qrcv_borderSize="1dp" app:qrcv_cornerColor="@color/colorPrimaryDark" app:qrcv_cornerLength="20dp" app:qrcv_cornerSize="3dp" app:qrcv_isBarcode="false" app:qrcv_isOnlyDecodeScanBoxArea="true" app:qrcv_isScanLineReverse="true" app:qrcv_isShowDefaultGridScanLineDrawable="true" app:qrcv_isShowDefaultScanLineDrawable="false" app:qrcv_isShowTipBackground="true" app:qrcv_isShowTipTextAsSingleLine="false" app:qrcv_isTipTextBelowRect="false" app:qrcv_maskColor="#33FFFFFF" app:qrcv_qrCodeTipText="将二维码/条码放入框内,即可自动扫描" app:qrcv_rectWidth="200dp" app:qrcv_scanLineColor="@color/colorPrimaryDark" app:qrcv_scanLineMargin="0dp" app:qrcv_scanLineSize="1dp" app:qrcv_tipTextColor="@android:color/white" app:qrcv_tipTextSize="12sp" app:qrcv_toolbarHeight="56dp" app:qrcv_topOffset="90dp" />
<android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:layout_alignParentTop="true" android:background="@color/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> <ImageView android:id="@+id/iv_torch" android:layout_height="@dimen/height_button" android:layout_width="@dimen/height_button" android:background="@drawable/bg_circle_dark" android:padding="12dp" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:layout_marginBottom="24dp" android:src="@drawable/ic_bt_torch_normal"/> </RelativeLayout>
2.调用如下: @BindView(R.id.zxingview) ZXingView zxingview; @BindView(R.id.iv_torch) ImageView ivTorch; boolean isOpenFlashlight;
@Override protected int provideContentViewId() { return R.layout.activity_warehouse_out_stock; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); /* tv_title.setText(R.string.repository_scan_out); mActionBar.setDisplayShowTitleEnabled(false); mActionBar.setDisplayHomeAsUpEnabled(true);*/ } @Override protected void onStart() { super.onStart(); zxingview.startCamera(); //zxingview.startSpotAndShowRect();
// mQRCodeView.startCamera(Camera.CameraInfo.CAMERA_FACING_FRONT); }
@Override protected void onStop() { zxingview.stopCamera(); //zxingview.stopSpotAndHiddenRect(); super.onStop(); } @Override protected void onDestroy() { zxingview.onDestroy(); super.onDestroy(); } private void vibrate() { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(200); } @Override public void onScanQRCodeSuccess(String result) { ToastUtils.showShortTime(result); vibrate(); zxingview.startSpot(); } @Override public void onScanQRCodeOpenCameraError() { Toast.makeText(this, "onScanQRCodeOpenCameraError", Toast.LENGTH_SHORT).show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } @OnClick(R.id.iv_torch) public void onClick() { zxingview.startSpotAndShowRect();
/* if (isOpenFlashlight) { zxingview.startSpotAndShowRect(); ivTorch.setImageResource(R.drawable.ic_bt_torch_normal); zxingview.closeFlashlight(); isOpenFlashlight = false;
} else { ivTorch.setImageResource(R.drawable.ic_bt_torch_pressed); zxingview.openFlashlight(); isOpenFlashlight = true; }*/ }
3.我debug 了一下卡在 rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));:
@Override public String processData(byte[] data, int width, int height) { String result = null; Result rawResult = null;
try { PlanarYUVLuminanceSource source = null; Rect rect = mScanBoxView.getScanBoxAreaRect(height); if (rect != null) { source = new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height(), false); } else { source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false); } rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source))); } catch (Exception e) { } finally { mMultiFormatReader.reset(); } if (rawResult != null) { result = rawResult.getText(); } return result; }
扫条码有时识别不了 怎么弄
@JakeWang123 并没有看到你提的是什么问题!
@wuyingtong 用 v1.1.8 版本
1.布局如下 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/fragmentContainer" android:layout_width="match_parent" android:layout_height="match_parent"
2.调用如下: @BindView(R.id.zxingview) ZXingView zxingview; @BindView(R.id.iv_torch) ImageView ivTorch; boolean isOpenFlashlight;
// mQRCodeView.startCamera(Camera.CameraInfo.CAMERA_FACING_FRONT); }
/* if (isOpenFlashlight) { zxingview.startSpotAndShowRect(); ivTorch.setImageResource(R.drawable.ic_bt_torch_normal); zxingview.closeFlashlight(); isOpenFlashlight = false;
3.我debug 了一下卡在 rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));:
@Override public String processData(byte[] data, int width, int height) { String result = null; Result rawResult = null;