首页 > 代码库 > 实现拍照和获取本地图片功能
实现拍照和获取本地图片功能
/* @flow */ import React, { Component } from ‘react‘; import { View, Text, StyleSheet, Button, Image, TouchableOpacity, Dimensions, TextInput, ToastAndroid, } from ‘react-native‘; const ImageUrl=‘http://192.168.127.1:8080‘; import ActionSheet from ‘react-native-actionsheet‘; const options = [ ‘取消‘, ‘本地图库‘, ‘拍照‘]; const title = ‘请选择‘; export default class SetView extends Component { constructor(props) { super(props) this.state = { selected: ‘‘, image:‘‘, } this.handlePress = this.handlePress.bind(this) this.showActionSheet = this.showActionSheet.bind(this) } showActionSheet() { this.ActionSheet.show() } handlePress(i) { if(i == 1){ console.log(‘本地图册‘); Expo.ImagePicker.launchImageLibraryAsync() .then((info)=>{ this.setState({image:info.uri}); this.settingUserImage(); }) }else if(i == 2){ console.log(‘拍照‘); Expo.ImagePicker.launchCameraAsync() .then((info)=>{ this.setState({image:info.uri}); }) } } render() { return ( <View style={styles.container}> <ActionSheet ref={o => this.ActionSheet = o} title={title} options={options} cancelButtonIndex={0} destructiveButtonIndex={3} onPress={this.handlePress} /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, }, });
import ActionSheet from‘react-native-actionsheet‘;
实现拍照和获取本地图片功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。