一段时间以来,我一直在寻找有关如何使用 React Native 在图像中绘制矩形的引用资料,但一无所获。
我尝试做的是将函数、照片和矩形对 Angular 线顶点的坐标作为参数传递,然后返回包含绘制的矩形的图像。我怎么能那样做?
最佳答案
想简单.. 就像创建带有背景颜色的 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%'
},
});
结果:
关于javascript - 如何在 React native 中的图像中绘制矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55944350/