Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 如何将本地映像文件路径写入uri路径_React Native_Expo_React Native Snap Carousel - Fatal编程技术网

React native 如何将本地映像文件路径写入uri路径

React native 如何将本地映像文件路径写入uri路径,react-native,expo,react-native-snap-carousel,React Native,Expo,React Native Snap Carousel,我想将本地映像文件路径转换为uri路径,以便在需要网站的地方放置本地映像目录,而不是uri。 我在下面显示代码 state = { search: '', images: [ '../../assets/assets/img/formula.png', //***this is not working 'https://source.unsplash.com/1024x768/?water',

我想将本地映像文件路径转换为uri路径,以便在需要网站的地方放置本地映像目录,而不是uri。 我在下面显示代码

state = {
        search: '',
        images: [
            '../../assets/assets/img/formula.png',  //***this  is not working
            'https://source.unsplash.com/1024x768/?water',
            'https://source.unsplash.com/1024x768/?girl',
            'https://source.unsplash.com/1024x768/?tree'
          ]
      };


//Image is used here..

<SliderBox images={this.state.images} />
状态={
搜索:“”,
图像:[
“../../assets/assets/img/formula.png”,//***这不起作用
'https://source.unsplash.com/1024x768/?water',
'https://source.unsplash.com/1024x768/?girl',
'https://source.unsplash.com/1024x768/?tree'
]
};
//这里使用的是图像。。
在图像数组中,我希望第一个图像必须包含来自本地文件图像的图像。
请有人告诉我如何做,以便在图像中包括我的本地图像文件路径

您需要导入例如:

import Formula from '../../assets/assets/img/formula.png';
然后你可以使用公式作为图像!
您也可以使用
require('../../assets/assets/img/formula.png')

您需要导入例如:

import Formula from '../../assets/assets/img/formula.png';
然后你可以使用公式作为图像!
您也可以使用
require('../../assets/assets/img/formula.png')

有点晚了,但希望它能帮助一些人。您可以使用
Image
中的
resolveAssetSource
,因此返回到您的代码时,它看起来是这样的

state = {
    search: '',
    images: [
        Image.resolveAssetSource(require("../../assets/assets/img/formula.png")).uri,
        'https://source.unsplash.com/1024x768/?water',
        'https://source.unsplash.com/1024x768/?girl',
        'https://source.unsplash.com/1024x768/?tree'
      ]
  };
当然,您需要先导入
图像

import { Image } from "react-native";

有点晚了,但希望它能帮助别人。您可以使用
Image
中的
resolveAssetSource
,因此返回到您的代码时,它看起来是这样的

state = {
    search: '',
    images: [
        Image.resolveAssetSource(require("../../assets/assets/img/formula.png")).uri,
        'https://source.unsplash.com/1024x768/?water',
        'https://source.unsplash.com/1024x768/?girl',
        'https://source.unsplash.com/1024x768/?tree'
      ]
  };
当然,您需要先导入
图像

import { Image } from "react-native";

但不工作,作为数组。即images数组元素期望图像为uri格式。可以这样说,注释部分iamge对象作为本地图像文件,但在那里它期望uri路径,因此如何将该本地图像路径转换为uri,以便我可以使用它,但不工作,作为一个数组。即images数组元素期望图像为uri格式。可以这样说,注释的部分iamge对象是作为本地图像文件的,但在那里它期望uri路径,因此如何将该本地图像路径转换为uri,以便我可以在那里使用它