Nekshay commited on
Commit
9c8790e
·
1 Parent(s): fd264ce

Update mobileapp.txt

Browse files
Files changed (1) hide show
  1. mobileapp.txt +50 -0
mobileapp.txt CHANGED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react';
2
+ import { View, Image, TouchableOpacity, Text } from 'react-native';
3
+ import ImagePicker from 'react-native-image-picker';
4
+ import { ImageEditor } from 'react-native';
5
+
6
+ const CropImage = () => {
7
+ const [croppedImage, setCroppedImage] = useState(null); // State to store the cropped image URI
8
+
9
+ const handleSelectImage = () => {
10
+ ImagePicker.showImagePicker({ mediaType: 'photo' }, (response) => {
11
+ if (!response.didCancel) {
12
+ const { uri } = response;
13
+ cropImage(uri);
14
+ }
15
+ });
16
+ };
17
+
18
+ const cropImage = (imageUri) => {
19
+ const cropData = {
20
+ offset: { x: 100, y: 100 }, // x, y coordinates to start cropping
21
+ size: { width: 200, height: 200 }, // width, height of the cropped area
22
+ displaySize: { width: 200, height: 200 }, // desired width, height of the cropped image
23
+ resizeMode: 'contain', // resizing mode
24
+ };
25
+
26
+ ImageEditor.cropImage(
27
+ imageUri,
28
+ cropData,
29
+ (croppedURI) => {
30
+ // Handle the cropped image URI
31
+ console.log('Cropped image URI:', croppedURI);
32
+ setCroppedImage({ uri: croppedURI });
33
+ },
34
+ (error) => {
35
+ console.error('Error cropping image:', error);
36
+ }
37
+ );
38
+ };
39
+
40
+ return (
41
+ <View>
42
+ <TouchableOpacity onPress={handleSelectImage}>
43
+ <Text>Select Image</Text>
44
+ </TouchableOpacity>
45
+ {croppedImage && <Image source={croppedImage} style={{ width: 200, height: 200 }} />}
46
+ </View>
47
+ );
48
+ };
49
+
50
+ export default CropImage;