Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native crop image

I have a little problem with cropping images in react native. As you can see the example below enter image description here

I want to crop the image inside the white rectangle, I don't know if I'm using the wrong formula or not

  takePicture = async() => {
    console.log("pic")
    if (this.camera != null) {
      const data = await this.camera.takePictureAsync();

      /**
       * Calcul
       */
      const x_axis_scale = data.width / width
      const y_axis_scale = data.height / height
      var x_coord_int = 70 * x_axis_scale;
      var y_coord_int = 120 * y_axis_scale;
      var rect_width_int = 200 * x_axis_scale;
      var rect_height_int = 70 * y_axis_scale
      const res = await ImageEditor.cropImage(data.uri, {
        offset: {x: x_coord_int, y: y_coord_int},
        size: {
          width:rect_width_int,
          height: rect_height_int
        }
      })
      this.setState({
        imageCrop: res
      })
    }
  };

It doesn'tt crop correcty. Any help?

like image 928
Mohamed Amine Bejaoui Avatar asked Nov 06 '22 10:11

Mohamed Amine Bejaoui


1 Answers

Sorry , i can't help about this issue . But there is a library react-native-image-crop-picker which can help with cropping issue . Hope this helps.

like image 181
Farhan Tanvir Avatar answered Nov 15 '22 07:11

Farhan Tanvir