mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
6.72k stars 1k forks source link

💭 Android Camera view width/height and photo width/height not the same. #2875

Closed OlviXhaferaj closed 2 weeks ago

OlviXhaferaj commented 2 weeks ago

Question

So I take the photo with camera.current.takePhoto function. The problem that I am facing, in android specifically, is that when I take a photo, if the camera view is set to, lets say, 370 width 700 height, the width of the photo is bigger or smaller than the view of the camera. For example if I resized the photo, it would be 400 width 700 height or something like that (this are just numbers to demonstrate).

What I saw is that the photo width output is different if I play with the photoResolution. If i set it to max, the photo width is bigger than what the camera sees, while if I dont set the photoResolution, the camera defaults to the best next resolution i guess, and the width appears to be smaller than the width of the view of the camera.

I want to take a photo and the output of it should be equal to the view that is presented to the user, not bigger or smaller than what the user sees.

Reason why this is a problem for me is because I want to make some automatic croping. The photo width/height ratio should be the same as the width/height ratio of the camera view.

If someone has some answer, would be appreciated!

What I tried

What I tried to solve this is setting the resizeMode="contain", and tried to understand how setting the format would work and change things.

VisionCamera Version

3.9.2

Additional information

mrousavy commented 2 weeks ago

This is not how cameras work. There are fixed formats for the Camera, and you need to find a format that most closely matches what you desire - then do some cropping afterwards to get exact permissions.