javascript - 如何在 React native 中的图像中绘制矩形

标签 javascript image react-native

一段时间以来,我一直在寻找有关如何使用 React Native 在图像中绘制矩形的引用资料,但一无所获。

我尝试做的是将函数、照片和矩形对 Angular 线顶点的坐标作为参数传递,然后返回包含绘制的矩形的图像。我怎么能那样做?

Example

最佳答案

想简单.. 就像创建带有背景颜色的 div 一样。 这是示例:

import * as React from 'react';
import { Text, View, StyleSheet, Image } from 'react-native';
import { Constants } from 'expo';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.rectangle}></View>
        <Image source={require('assets/snack-icon.png')} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
    position: 'relative',
  },
  rectangle: {
    height: 128,
    width: 128,
    backgroundColor: 'salmon',
    position: 'absolute', 
    zIndex: 99,
    top: '50%',
    left: '40%'
  },

});

结果:

enter image description here

关于javascript - 如何在 React native 中的图像中绘制矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55944350/

相关文章:

android - 找不到符号 Android React Native

reactjs - 你如何导航到另一个不接收 react 导航 Prop 的组件?

javascript - 即使未成功,状态值也会在 onSubmit 后重置

javascript - 如何将 JSON 数组转换为单个 JSON 字符串?

javascript - Drupal 表单 API #States

php - 以 zend 形式添加 img 标签

javascript - Meteor 和 Phaser - 加载资源时出错

javascript - 所有图片加载完毕后执行代码

c++ - 清晰缩放图像的算法

react-native - 如何在 React-Navigation/Drawer 6 中实现 'goBack'