Skip to content

[Android][react-native] incorrect image width and height - CloseableImage getWidth/getHeight #2236

Closed

Description

@Fsarmento

Description

On react native, Image.getSize() uses Fresco (here) to return the width and height of a given image.

As explaned in this react-native issue (react/react-native#22145), the returned width and height are inconsistent in Android. The ratio between width and height is correct, but the values of width and height are not.

Reproduction

See example in react/react-native#22145

Additional Information

react: 16.5.0 => 16.5.0
react-native: 0.57.1 => 0.57.1

  • Fresco version: com.facebook.fresco:fresco-1.10.0
  • Platform version: Android 6.0.1 (One plus One); Android 7.0 (Huawei MediaPad T3 10);

Activity

  1. erikandre commented on Nov 7, 2018

    @erikandre
    Contributor

    Hi @Fsarmento

    Thanks for reporting this.
    @oprisnik - do you have any idea what might be behind this issue?

  2. oprisnik commented on Nov 7, 2018

    @oprisnik
    Contributor

    My best guess would be that your RN setup is using downsampling to downsample images. Fresco reports the size of the decoded bitmap, which in this case would be the downsampled image. In your case, it looks like a downsampling factor of 2 was applied. IMO, this is the correct thing to return here.

    @Fsarmento, can you check if downsampling is indeed enabled for your app (see https://frescolib.org/docs/resizing.html)? Disabling it should give you the correct dimensions.

  3. Fsarmento commented on Nov 7, 2018

    @Fsarmento
    Author

    Hi @oprisnik.
    According to your link, downsampling is enabled with .setDownsampleEnabled(true).

    I looked in my whole app and in react-native repository and this method is only called in one place, here, and is set to false.

    I know that Image component in react-native have the option to select the resize method. From what I looked, downsampling is set by calling setResizeOptions. This is only used in ReactImageView.java , which is not used by Image.getSize.

  4. oprisnik commented on Nov 14, 2018

    @oprisnik
    Contributor

    Does this only happen for huge images? If so, we are automatically downsampling huge images (I think right now > 2048 px). However, this is configurable since ed5c075 and can be adjusted to whatever you like.

    You can raise the limit (and it might crash on some devices that can't handle huge bitmaps).

    Otherwise, you can get the EncodedImage, which should give you the original image dimensions (which could be different to the decoded bitmap dimensions as you've noticed).

  5. bartolkaruza commented on Dec 29, 2018

    @bartolkaruza

    @oprisnik I think you can close this issue, as the downsampling seems to be the cause and the downsampled value is more useful for layout concerns. People are ending up on react/react-native#22145 because they want to use Image.getSize for image processing after taking an image from a camera. The reason this is even used by people is this bug on the react-native-camera repo which returns the captured image size, but with a delay: react-native-camera/react-native-camera#768

    In short IMO, won't fix on React Native and not a bug for Fresco. Thanks for your help.

  6. leighman commented on Jan 3, 2019

    @leighman

    Did something change in 0.57 related to this. Seems like a regression / huge change not mentioned in release notes?
    See react/react-native#22145 (comment)

  7. AInoob commented on Feb 4, 2020

    @AInoob

    If you are using Expo, then you can use ImageManipulator.manipulateAsync to flip the image and get the REAL image size.
    https://docs.expo.io/versions/v36.0.0/sdk/imagemanipulator/

  8. laurent22 commented on Sep 25, 2023

    @laurent22

    That's a very old issue but it's still happening (see laurent22/joplin#8856). Specifically, a user gave us this image, which is 4348 × 3251 pixels but incorrectly detected as 1087 x 813 pixels:

    20230909_190715.jpg.zip

    Is there any plan to fix this?

  9. added a commit that references this issue on May 12, 2026
    8823a80
  10. added a commit that references this issue on May 18, 2026
    ff84256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions