实现拍照和获取本地图片功能
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现拍照和获取本地图片功能相关的知识,希望对你有一定的参考价值。
/* @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‘;
以上是关于实现拍照和获取本地图片功能的主要内容,如果未能解决你的问题,请参考以下文章
用php实现手机拍照+本地相册实现图片上传功能,需要统一样式