MCPcopy
hub / github.com/cyrildiagne/ar-cutpaste / App

Function App

app/App.tsx:41–208  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39}
40
41export default function App() {
42 const [state, setState] = useState({
43 hasPermission: false,
44 type: Camera.Constants.Type.back,
45 camera: null,
46 currImgSrc: "",
47 } as State);
48
49 const [pressed, setPressed] = useState(false);
50 const [pasting, setPasting] = useState(false);
51
52 let camera: any = null;
53
54 useEffect(() => {
55 (async () => {
56 // Ping the server on startup.
57 server.ping();
58 // Request permission.
59 const { status } = await Camera.requestPermissionsAsync();
60 const hasPermission = status === "granted" ? true : false;
61 setState({ ...state, hasPermission });
62 })();
63 }, []);
64
65 async function cut(): Promise<string> {
66 const start = Date.now();
67 console.log("");
68 console.log("Cut");
69
70 console.log(camera.pictureSize);
71 // const ratios = await camera.getSupportedRatiosAsync()
72 // console.log(ratios)
73 // const sizes = await camera.getAvailablePictureSizeAsync("2:1")
74 // console.log(sizes)
75
76 console.log("> taking image...");
77 const opts = { skipProcessing: true, exif: false, quality: 0 };
78 // const opts = {};
79 let photo = await camera.takePictureAsync(opts);
80
81 console.log("> resizing...");
82 const { uri } = await ImageManipulator.manipulateAsync(
83 photo.uri,
84 [
85 { resize: { width: 256, height: 512 } },
86 { crop: { originX: 0, originY: 128, width: 256, height: 256 } },
87 // { resize: { width: 256, height: 457 } },
88 // { crop: { originX: 0, originY: 99, width: 256, height: 256 } },
89 // { resize: { width: 256, height: 341 } },
90 // { crop: { originX: 0, originY: 42, width: 256, height: 256 } },
91 ]
92 // { compress: 0, format: ImageManipulator.SaveFormat.JPEG, base64: false }
93 );
94
95 console.log("> sending to /cut...");
96 const resp = await server.cut(uri);
97
98 console.log(`Done in ${((Date.now() - start) / 1000).toFixed(3)}s`);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected