android - 如何将@2x @3x 图像集成到 React Native 项目(Android 和 IOS)?

标签 android reactjs image react-native resolution

我已将相同图像的版本 (@2x @3x) 添加到 src>assets 以在所有设备上运行我们的平台。这是问题所在,VSCode 仅识别即 path.png(它不识别 @2x 和 @3x)。我们如何处理这个问题?

最佳答案

React native 会自动从 3 个可用选项中选择所需的图像,即 1x、2x、3x。我们只需提供基本图像的文件名。

示例

.
├── button.js
└── img
    ├── check.png
    ├── check@2x.png
    └── check@3x.png

因此,如上所述,当您必须使用支票图像时,只需为 check.png 提供图像路径,其余部分将根据 android 和 ios 设备的设备屏幕密度由 react native 自动处理。< br/> 像下面一样使用图像,一切都像魅力一样。

<Image source={require('./img/check.png')} />

More you can read here about the images from react native official docs.

我希望这会有所帮助....谢谢 :)

关于android - 如何将@2x @3x 图像集成到 React Native 项目(Android 和 IOS)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59026204/

相关文章:

javascript - Android Phonegap 3 webapp 白名单不起作用

android - Google Play 控制台报告应用程序崩溃,我无法重现

javascript - Jest 测试用例失败 - ReferenceError : Office is not defined

android - 需要让TextView自动垂直滚动

java - 获取 jsonarray 键名

reactjs - 通过包装器组件控制 Flatpickr 日历 View 的打开/关闭

javascript - 如何在 React 中呈现选中的单选按钮

javascript - 删除具有一定宽度和高度的图像

c# - ImageFailed 与 GridView

python - 无法去除透明度,PIL getbbox() 和 Numpy 都不起作用