0

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
      }}
    />
A. Gopal Reddy
  • 370
  • 1
  • 3
  • 16

1 Answers1

0

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
      }}
    />
enzou
  • 318
  • 4
  • 12
  • I can able to load with this relative path with respect to the project. However, the requirement is to load from a fixed path as mentioned in the above question. – A. Gopal Reddy Apr 22 '22 at 05:25
  • Hmm in that case IMHO is convenience upload the img to some server, because when you compile the app the bundle doesn't has a C disk for example, the device doesn't has the folder structure that you're passing as argument, that folder path is valid in your computer – enzou Apr 22 '22 at 13:31
  • I mean, upload to some server or put the image in the project folder – enzou Apr 22 '22 at 13:32