How to crop image in React Native

In this React Native source code example, the source code below illustrate how to crop image in React Native.

You can copy and adopt this source code example to your React Native project without reinventing the wheel.

import React, {Component} from 'react';
import {StyleSheet, Text, View, Image} from 'react-native';
/*Please follow the instructions on setting up react-native-image-crop-picker*/
import ImagePicker from 'react-native-image-crop-picker';
import Permissions from 'react-native-permissions';

export default class App extends Component {
  state = {
     photoPermission:'',
     cameraPermission:''
   }

  componentDidMount() {
    Permissions.request('storage').then(response => {
          this.setState({ photoPermission: response })
    })
    Permissions.request('camera').then(response => {
          this.setState({ cameraPermission: response })
    })
   }


  SelectImage(){
    ImagePicker.openPicker({
          width: 150,
          height: 150,
          cropping: true
        }).then(image => {
          console.log(image);
        });
  }
  render() {
    return (
      <View style={styles.container}>
          <Text style={{padding: 20,backgroundColor:'#ddd'}} onPress={()=>this.SelectImage()}>Select Image</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  Image:{
    height: 250,
    width:250,
  },
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
});

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment