javascript - 如何在 React Native 中的图像中绘制矩形
问题描述
一段时间以来,我一直在寻找有关如何使用本机反应在图像中绘制矩形的参考资料,但我一无所获。
我尝试做的事情是像将函数、照片和矩形对角线顶点的坐标作为参数传递,然后返回带有该绘制矩形的图像。我怎么能那样做?
解决方案
想得简单..就像用背景颜色创建 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%'
},
});
结果:
推荐阅读
- c# - 我可以将 Dapper 查询的结果绑定到 IEnumerabe 以外的其他内容吗
不打破它? - node.js - 使用 JWT 令牌 + Shibboleth SSO 保护节点 JS API
- jquery - 将行添加到短表行不会插入到正确的位置
- knex.js - objectionjs 列引用不明确
- alloy - 为什么不能将空字段中的值的计数与整数进行比较?
- python - 如何将算术颜色转换为对应的 RGB?
- python - TensorFlow tf.map_fn 移除一个维度
- r - 使用 scale_colour_gradient 自定义 ggplot 热图中的颜色
- windows - 将库 (DLL) 显式加载到旧版函数指针中
- redux - 基于规则的 redux 可观察史诗中的多个动作