我正在尝试使用 react-native imagepicker 库创建一个可重用的函数,但是当我导入该函数时,我从导入它的组件中获得了未定义的信息。使用 console.log 我看到它实际工作。它只是没有显示上传的图像。
我尝试返回源和实际功能,但它不起作用
辅助函数.js
import ImagePicker from 'react-native-image-picker';
export const photoUpload =()=>{
const options = {
title: 'Select Avatar',
camera: [{ name: 'fb', title: 'Take a picture' }],
storageOptions: {
skipBackup: true,
path: 'images',
},
};
const action = ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.camera) {
console.log('User tapped custom button: ', response.camera);
} else …Run Code Online (Sandbox Code Playgroud) 我正在通过博览会运行我的反应本机应用程序。 React-native-image-picker 也发生了同样的事情。
我尝试使用react-native link react-native-image-picker和react-native link react-native-image-crop-picker。它不起作用,所以我尝试取消链接并再次链接,但仍然不起作用。我尝试了各种方法,也尝试了不同版本的react-native和react-native-image-picker以及react-native-image-crop-picker。
链接到 npm 库:-
图像选择器-> https://www.npmjs.com/package/react-native-image-crop-picker/v/0.4.2
image-crop-picker -> https://github.com/react-native-community/react-native-image-picker
React-native-image-picker 的代码:-
import ImagePicker from 'react-native-image-picker';
// More info on all the options is below in the API Reference... just some common use cases shown here
const options = {
title: 'Select Avatar',
customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
storageOptions: {
skipBackup: true,
path: 'images',
},
};
/**
* The first arg is the options object …Run Code Online (Sandbox Code Playgroud)我正在学习一些有关 React Native 的知识,但出现了一个我无法解决的问题。
\n\n我正在使用react-native-image-picker 我已经能够从我的设备拍摄照片,问题是我无法在设备屏幕上显示捕获的图像。
\n\n这是我的代码。
\n\nimport React from \'react\';\nimport { Button, Image, View} from \'react-native\';\n\nimport ImagePicker from \'react-native-image-picker\';\n\n\nconst TomarFoto = () => {\n const tomarFoto = () => {\n ImagePicker.launchCamera({}, (response) => {\n console.log(\'Respuesta =\', response);\n if (response.didCancel) {\n alert(\'Subida cancelada\');\n } else if (response.error) {\n alert(\'Error encontrado: \', error);\n } else {\n const source = {uri:response.uri};\n }\n });\n };\n\n return (\n\n <View style={{ flex: 1, alignItems: \'center\', justifyContent: \'center\' }}>\n <Image\n source={ uri:response.uri}\n style={ …Run Code Online (Sandbox Code Playgroud) 我正在使用"react-native-image-picker": "^3.0.1"本机来捕获图像。但我在 android 9 中打开相机时出错。
我有错误:
{"errorCode": "others", "errorMessage": "This library does not require Manifest.permission.CAMERA, if you add this permission in manifest then you have to obtain the same."}
Run Code Online (Sandbox Code Playgroud)
这是我的代码
{"errorCode": "others", "errorMessage": "This library does not require Manifest.permission.CAMERA, if you add this permission in manifest then you have to obtain the same."}
Run Code Online (Sandbox Code Playgroud)
android android-camera react-native react-native-image-picker
我正在使用 React-Native-Image-Picker 从我的应用程序中选择和上传文件,我面临的问题是它在 Android 中工作,但在 ios 中,react-native-image-picker 对话框在启动后自动关闭,因此我无法选择供上传的文件。ios 文件上传所需的所有权限也已被授予。
import ImagePicker from 'react-native-image-picker';
import RNFetchBlob from 'react-native-fetch-blob';
var options = {
title: 'Select Image',
quality : 0.25,
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.showImagePicker(options, response => {
console.log('Response = ', response);
RNFetchBlob.fs.stat(response.path)
.then((stats) => {
if (stats.size <= 5000000) {
let source = response;
let checkboxStates = {...this.state.checkboxStates};
checkboxStates['image'] = true;
this.setState({ imagePath: source, imageVisible: true, totalUploadSize: this.state.totalUploadSize + stats.size });
this.setState({checkboxStates});
}
else{
toastMessage('Image should …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个小型应用程序,我想将相机胶卷中的图像加载到应用程序中。我已经在 Expo Image Picker 文档的帮助下构建了一个组件来执行此操作。遗憾的是,我总是在我的博览会客户端中收到以下警告,并且我无法从相机胶卷中选取任何图像。当我单击按钮选择它们时,它就保持原样。
我的代码:
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!');
}
}; …Run Code Online (Sandbox Code Playgroud) javascript reactjs react-native expo react-native-image-picker