Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 世博会图像选择器:未处理的承诺拒绝:TypeError:undefined不是对象_Javascript_Reactjs_React Native_Expo_React Native Image Picker - Fatal编程技术网

Javascript 世博会图像选择器:未处理的承诺拒绝:TypeError:undefined不是对象

Javascript 世博会图像选择器:未处理的承诺拒绝:TypeError:undefined不是对象,javascript,reactjs,react-native,expo,react-native-image-picker,Javascript,Reactjs,React Native,Expo,React Native Image Picker,我目前正在开发一个小应用程序,我希望将摄像头中的图像加载到该应用程序中。我在世博会图像采集器文档的帮助下构建了一个组件。可悲的是,我的expo客户端总是收到以下警告,我无法从摄像头中拾取任何图像。当我点击按钮选择它们时,它保持原样 我的代码: import React, {useEffect, useState} from 'react'; import { View, Image, TouchableOpacity, PermissionsAndroid, Alert, Platform, S

我目前正在开发一个小应用程序,我希望将摄像头中的图像加载到该应用程序中。我在世博会图像采集器文档的帮助下构建了一个组件。可悲的是,我的expo客户端总是收到以下警告,我无法从摄像头中拾取任何图像。当我点击按钮选择它们时,它保持原样

我的代码:

import React, {useEffect, useState} from 'react';
import { View, Image, TouchableOpacity, PermissionsAndroid, Alert, Platform, StyleSheet } from 'react-native';
import * as Permissions from 'expo-permissions';
import ImagePicker from 'expo-image-picker';
import { MaterialIcons } from '@expo/vector-icons'

export default function ImageChooser() {
    const [imageSource, setImageSource] = useState([]);

    getPermissionAsync = async () => {
        
          const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
          if (status !== 'granted') {
            alert('Sorry, we need camera roll permissions to make this work!');
          }
          
    };
    
    useEffect(() => {
        getPermissionAsync();
    }, []);
    
    _getPhotoLibrary = async () => {
        let result = await ImagePicker.launchImageLibraryAsync({
         allowsEditing: true,
         aspect: [4, 3]
        });
        if (!result.cancelled) {
         setImageSource({ image: result.uri });
        }
    }
    

    return (
        <View style={styles.container}>
            <TouchableOpacity style={styles.button} onPress={() => _getPhotoLibrary()}>
                {!imageSource && <MaterialIcons name="add-a-photo" style={styles.icon} size={36} />}
                {/* {imageSource && <Image source={{uri:imageSource}} style={styles.image} />} */}
            </TouchableOpacity>
        </View>
    )
}

const styles = StyleSheet.create({
    container: {
        paddingLeft: 20,
        paddingVertical: 10
    },    
    button: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
        width: 200,
        height: 150,
        borderWidth: 1,
        borderColor: '#C6C6C8',
        borderRadius: 5,
        backgroundColor: '#fff'
    },
    image: {
        width: 200,
        height: 150
    },
    icon: {
        color: '#C6C6C8'
    }
})

您正在错误地导入
图像选择器

使用
import*作为“世博会图像采集器”中的图像采集器


以下是参考文档:

您导入的
图像选择器不正确

使用
import*作为“世博会图像采集器”中的图像采集器


这是参考文档:

谢谢!这就解决了:)谢谢!这就解决了:)
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_expoImagePicker.default.launchImageLibraryAsync')]
* components/ImageChooser.js:23:23 in _getPhotoLibrary
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:293:29 in invoke
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:154:27 in invoke
- node_modules/regenerator-runtime/runtime.js:189:16 in PromiseImpl$argument_0
- node_modules/react-native/node_modules/promise/setimmediate/core.js:45:6 in tryCallTwo
- node_modules/react-native/node_modules/promise/setimmediate/core.js:200:22 in doResolve
- node_modules/react-native/node_modules/promise/setimmediate/core.js:66:11 in Promise
- node_modules/regenerator-runtime/runtime.js:188:15 in callInvokeWithMethodAndArg
- node_modules/regenerator-runtime/runtime.js:211:38 in enqueue
- node_modules/regenerator-runtime/runtime.js:238:8 in exports.async
* components/ImageChooser.js:23:23 in _getPhotoLibrary
* components/ImageChooser.js:36:61 in TouchableOpacity.props.onPress
- node_modules/react-native/Libraries/Pressability/Pressability.js:691:17 in _performTransitionSideEffects
- node_modules/react-native/Libraries/Pressability/Pressability.js:628:6 in _receiveSignal
- node_modules/react-native/Libraries/Pressability/Pressability.js:524:8 in responderEventHandlers.onResponderRelease
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:265:4 in invokeGuardedCallbackImpl
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:476:2 in invokeGuardedCallback
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:500:2 in invokeGuardedCallbackAndCatchFirstError
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:597:41 in executeDispatch
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:621:19 in executeDispatchesInOrder
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2521:28 in executeDispatchesAndRelease
* [native code]:null in forEach
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:836:4 in forEachAccumulated
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2546:20 in runEventsInBatch
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2702:18 in runExtractedPluginEventsInBatch
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2639:35 in batchedUpdates$argument_0
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:17712:13 in batchedUpdates$1
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2492:29 in batchedUpdates
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2638:16 in _receiveRootNodeIDEvent
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:2767:27 in receiveTouches
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue