Open karthiarjun opened 2 years ago
Fixes: In ios the response returns "{"assets": [{"fileName": "E13E8B4A-D760-4604-BEB1-2432B276635E.png",......
Below code can fix the error: let jsonRes = response.assets[0].uri; console.log("Image Picker Response: ", jsonRes); if (jsonRes == null) { throw new Error('oh!'); } ......
Hi, We can pick up the image from local. However, a promise rejection warning has popped up with an empty screen.
Code: / eslint-disable react-native/no-inline-styles / import React, { useState, useEffect } from "react"; import { StyleSheet, View, Button, SafeAreaView, ScrollView, Text, Dimensions, ActivityIndicator, } from 'react-native'; import { ImagePickerResponse, launchImageLibrary, } from 'react-native-image-picker'; import MlkitOcr, { MlkitOcrResult } from 'react-native-mlkit-ocr';
export default function App() { const [loading, setLoading] = useState(false); const [result, setResult] = useState(MlkitOcrResult); const [image, setImage] = useState(ImagePickerResponse);
if (loading) { return (
} return (
); }
function fitWidth(value: number, imageWidth: number) { const fullWidth = Dimensions.get('window').width; return (value / imageWidth) * fullWidth; }
function fitHeight(value: number, imageHeight: number) { const fullHeight = Dimensions.get('window').height; return (value / imageHeight) * fullHeight; }
function launchGallery( setResult: (result: MlkitOcrResult) => void, setImage: (result: ImagePickerResponse) => void, setLoading: (value: boolean) => void ) { launchImageLibrary( { mediaType: 'photo', }, async (response: ImagePickerResponse) => { // response.uri = "../images/TextRead.png" if (!response.uri) { throw new Error('oh!'); } try { setImage(response);
); }
const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', }, scroll: { flex: 1, width: '100%', borderColor: '#ccc', borderWidth: 2, }, });