我想在 PixelRatio 中使用 react-native 但不确定我在哪里插入我的图像路径。在 react 原生文档中,我在 pixelRatio 中使用时没有看到任何关于图像路径的提及
var image = getImage({
width: PixelRatio.getPixelSizeForLayoutSize(200),
height: PixelRatio.getPixelSizeForLayoutSize(100),
});
<Image source={image} style={{width: 200, height: 100}} />
这里的来源是图像维度,但假设我有 URL,在哪里写?在 react 的图像文档中,我必须编写它而不是源代码,例如
<Image
style={{width: 50, height: 50}}
source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
/>
那么当我使用PixelRatio时,正确的方法是什么?
Image.source
prop 是一个普通的对象描述符,它采用属性uri
、width
和height
(以及其他图像源类型,例如嵌入式资源)。
您应该能够自己构建图像源:
const image = {
uri: 'https://facebook.github.io/react/img/logo_og.png',
width: PixelRatio.getPixelSizeForLayoutSize(200),
height: PixelRatio.getPixelSizeForLayoutSize(100)
};
return <Image source={image} />