Riten
Riten

Reputation: 2949

Could not load image of .JPG format

I was trying to load image from local resource whose format is .JPG. But every time it gives me following error.

enter image description here

Do react native support .JPG format ? Can anyone help me on this ? Thanks...

Upvotes: 4

Views: 3392

Answers (2)

Jonathan Stellwag
Jonathan Stellwag

Reputation: 4277

If you are sure that your image_path is right then you could rename the Image in your folder from the capital letters (.JPG) to lower case letters (.jpg).

Tested this case for Windows and could reproduce and fix it with the above solution.

react-native version: 0.23.1

For clarification:

var yourPicture = require('./yourPathToYourPicture/picture.jpg); //Working

var yourPicture = require('./yourPathToYourPicture/picture.JPG); //Not-Working

Solution to solve the capital letter problem: Save your picture in your project folder with lower case letters yourPicture.JPG -> yourPicture.jpg

Use your image

render(){
    return(
        <Image source={yourPicture}/>
    );
}

Upvotes: 1

Carlos Quiroga
Carlos Quiroga

Reputation: 1071

You must use Image from react-native

import {
  Image,
} from 'react-native';
...

Image have a prop called source

<Image source={require('./img/fotofondo_app.jpg')}/>

If the error still, try to execute react-native run-android beacuse the image files aren't read in hot.

Upvotes: 0

Related Questions