You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Android][react-native] incorrect image width and height - CloseableImage getWidth/getHeight #2236
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.
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.
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.
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).
@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.
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)
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:
Activity
erikandre commentedon Nov 7, 2018
Hi @Fsarmento
Thanks for reporting this.
@oprisnik - do you have any idea what might be behind this issue?
oprisnik commentedon Nov 7, 2018
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.
Fsarmento commentedon Nov 7, 2018
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 byImage.getSize.oprisnik commentedon Nov 14, 2018
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).bartolkaruza commentedon Dec 29, 2018
@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.getSizefor image processing after taking an image from a camera. The reason this is even used by people is this bug on thereact-native-camerarepo which returns the captured image size, but with a delay: react-native-camera/react-native-camera#768In short IMO, won't fix on React Native and not a bug for Fresco. Thanks for your help.
leighman commentedon Jan 3, 2019
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)
AInoob commentedon Feb 4, 2020
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/
laurent22 commentedon Sep 25, 2023
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?
Fix Image.getSize returning downsampled dimensions on Android (react#…
Fix Image.getSize returning downsampled dimensions on Android (#56736)