1

I am building simple application, but one problem is I lost a lot of time, that's why I write here, I have images in my app that I get from another server, I need to know the original size of the image, I used to use React-native getSize() method to get the right dimensions, it worked on IOS but on Android it was calculating incorrect dimensions, this happened when the size of the image was too large, after reading a few articles and comments I analyzed that there might have been a problem in Fresco, I was unable to solve this problem.

//returns wrong dimensions
Image.getSize(myUri, (width, height) => {setState({width, height})});

 const setImageSize = (imageUrl:any) => {
        const img = new Image();
        img.src =`https:${imageUrl}`;
        img.onload = () => {
           console.log(
            "height-:", img.height,
            "width-:", img.width
            );
           
        };
   };

  useEffect(()=>{
     setImageSize(image)
  },[])

After that I tried to write a function that would call this url and would get dimensions, but I can not create constructor function with new Image() it's throws error TypeError: Object is not a constructor (evaluating 'new _reactNativeElements.Image()'). I do not know what to do or where to find the solution. thank you

Nightcrawler
  • 943
  • 1
  • 11
  • 32

1 Answers1

0
Image.getSize(myUri, (width, height) => { this.setState({ width, height }) });

Refer to this!