Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw square to tag an object. (React Native)

I see many mobile apps having a feature that user can draw a square to indicate something to tag on the image.

I'm building Face Tagging app and basically user draws square on the boundary of human's face on the image.

I've Googled it many times but I'm not sure RN has some feature library for tagging.

How can I achieve this? Is there any good library to draw square on image? And it will be even better if I can remember its coordinate width, height, and position of the rectangle.

Any idea or suggestion will be highly appreciated!

This is an example below

enter image description here

like image 995
merry-go-round Avatar asked Oct 21 '17 14:10

merry-go-round


People also ask

How do you add an image to an object in react native?

Open App. js and add the following code: import { StatusBar } from "expo-status-bar"; import React from "react"; import { StyleSheet, Text, View, ImageBackground } from "react-native"; const staticImage = require("./src/assets/static-image. png"); export default function App() { return ( <View style={styles.

How do you write an object in react native?

You might want to take a look at this for creating your "object" class: javascript.info/constructor-new. So instead, something like "function Man() { this.name = 'joe'; this. age = 27; this. country = 'France'; } export default man = new Man()", depending on what you're trying to do.

How do you make a curve shape in react native?

PI/180; const theta = degToRad(7); Putting all this together, you might adjust your code like so: const degToRad = (deg) => (deg * Math. PI) / 180; const radToDeg = (rad) => (rad * 180) / Math.


1 Answers

You can use React Native ART library to draw shapes on top of image. It is a standard library that ships with React Native (although not linked to the binary by default).

Regarding the algorithm:

  • Render an image
  • Overlay image with React Native's ART.Surface
  • Detect taps to get coordinates + overlay the rest of the image
  • Once you have coordinates of the tap, you can draw a shape you want
  • Stop drawing shape when user removes his finger (onPressOut event)

Where to go from here:

  • Basic tutorial, explaining how to wire up React Native and ART
  • Unofficial(there no official one) documentation
like image 188
Alexey Kureev Avatar answered Sep 21 '22 23:09

Alexey Kureev