反应原生视觉相机不从真实文档扫描pdf-417

问题描述 投票:0回答:1

我已经在我的 React Native 0.75 应用程序中实现了 React Native 视觉相机。

我的目标是扫描门票,其代码为 pdf-417

enter image description here

按照文档并进行一些测试,我已经能够验证pdf417扫描在ios上是否可以正常工作。但是,当使用 Android 扫描同一文档时,它不会读取销售收据的 pdf417。

我做了一些测试来解决这个问题,结果发现,当创建一个只有几个字符的pdf417时,可以读取它(页面创建pdf417cognex)。

但问题是选票有一个包含很多字符的标准(它是一个包含选票所有数据、社会原因、贸易惯例、金额、日期等的 Xml)。

这是我必须扫描的块:

import {Alert, Pressable, StyleSheet, Text, View} from 'react-native';
import {useAppState} from '@react-native-community/hooks';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {
  Camera,
  useCameraDevice,
  useCameraFormat,
  useCameraPermission,
  useCodeScanner,
} from 'react-native-vision-camera';
import {useIsFocused} from '@react-navigation/native';
import {Loader} from '../../components/Loader';
import type {Code} from 'react-native-vision-camera';
import {Icon, IconButton} from 'react-native-paper';

export const CameraScreen = () => {
  const [mode, setMode] = useState('camera');

  const device = useCameraDevice('back');

  const showCodeAlert = (value: string, onDismissed: () => void): void => {
    console.log('showCodeAlert', value);
    isShowingAlert.current = true;
    Alert.alert('Code Scanned', value, [
      {
        text: 'OK',
        onPress: () => {
          isShowingAlert.current = false;
          onDismissed();
        },
      },
    ]);
  };

  const isShowingAlert = useRef(false);

  const onCodeScanned = useCallback((codes: Code[]) => {
    console.log('onCodeScanned', codes);
    console.log(`Scanned ${codes.length} codes!`);
    const value = codes[0].value;
    console.log('Scanned value:', value);
    if (value == null) {
      return;
    }

    if (isShowingAlert.current) {
      return;
    }

    showCodeAlert(value, () => {
      isShowingAlert.current = false;
    });
    isShowingAlert.current = true;
  }, []);

  /*  const codeScanner = useCodeScanner({
    codeTypes: ['qr', 'ean-13', 'pdf-417', 'aztec', 'codabar'],
    onCodeScanned: onCodeScanned,
  }); */
  const codeScanner = useCodeScanner({
    codeTypes: ['qr', 'ean-13', 'code-128', 'code-39', 'pdf-417'],
    onCodeScanned: onCodeScanned,
  });

  const isFocused = useIsFocused();
  const appState = useAppState();
  const isActive = isFocused && appState === 'active';
  const {hasPermission, requestPermission} = useCameraPermission();

  const camera = useRef<Camera>(null);

  console.log('CameraScreen::Application::STATUS::AppState', appState);
  console.log('CameraScreen::Application::STATUS::isActive', isActive);

  console.log('cameraScreen::MODE', mode);

  useEffect(() => {
    if (!hasPermission) {
      requestPermission();
    }
  }, [hasPermission]);

  //console.log('has Permission?', hasPermission);

  const onCodeScanPress = () => {
    console.log('code scan pressed');
  };

  if (!hasPermission) {
    return <Loader />;
  }

  if (device == null) {
    return (
      <View style={StyleSheet.absoluteFill}>
        <Text>device error</Text>
      </View>
    );
  }

  return (
    <View style={{flex: 1}}>
      {device != null && (
        <Camera
          style={StyleSheet.absoluteFill}
          device={device}
          isActive={isActive}
          codeScanner={codeScanner}
          //torch={torch ? 'on' : 'off'}
          enableZoomGesture={true}
        />
      )}

      <View
        style={{
          position: 'absolute',
          top: 50,
          right: 20,
          padding: 5,
          borderRadius: 10,
          backgroundColor: 'rgba(0, 0, 0, 0.5)',
        }}>
        <IconButton
          icon={mode === 'camera' ? 'camera' : 'barcode-scan'}
          iconColor="white"
          size={30}
          onPress={() => setMode(mode === 'barcode' ? 'camera' : 'barcode')}
        />
      </View>
      <Pressable
        onPress={onCodeScanPress}
        style={{
          position: 'absolute',
          alignSelf: 'center',
          bottom: 50,
          width: 75,
          height: 75,
          borderRadius: 75,
          backgroundColor: 'white',
        }}
      />
    </View>
  );
};
react-native pdf417 react-native-vision-camera
1个回答
0
投票

你找到解决办法了吗?我也有同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.