How to show the image from the local file path example from c:/foldername/x.png

601 views Asked by At

I would like to show the image from the File path example from c:/foldername/x.png. When I have given file path, we are getting cross mark but it is not loading the image, anyone has any idea? Code which I was working

<Image source={require('C:/Users/username/Pictures/66.png')}
      style={{
        width:220,
        height:220,
        borderWidth:2,
        borderColor:'#d35647',
        resizeMode:'stretch',
        margin:8
      }}
    />
1

There are 1 answers

3
enzou On

If you have for example, the follow scafolding

src
|____/assets
|_________imgs
|_____________mi-img.png
|____/components
|_________/MyImage
|_____________MyComponent.js

in MyComponent.js you must access to your image in the follow way:

<Image source={require('../../assets/imgs/mi-img.png')}
      style={{
        width:220,
        height:220,
        borderWidth:2,
        borderColor:'#d35647',
        resizeMode:'stretch',
        margin:8
      }}
    />