I’m using expo-camera (CameraView to be precise) to take pictures in portrait mode of landscapes styles pictures. By doing so when I rotate them to visualize them in landscape, the height is very small compared to the width.
I’m trying to arrive to a result of 4:3 like for Iphone for exemple but I don’t succeed in changing the ratio/pictureSize of the photos I’m taking.
This is my code:
// CameraScreen.js
import React, { useRef, useState, useEffect } from 'react';
import { StyleSheet, View, Text, Button } from 'react-native';
import { CameraView, useCameraPermissions, getAvailablePictureSizesAsync } from 'expo-camera';
export default function CameraScreen({ navigation }) {
const cameraRef = useRef(null);
const [permission, requestPermission] = useCameraPermissions();
const [isTakingPicture, setIsTakingPicture] = useState(false);
const [enableTorch, setEnableTorch] = useState(false);
if (!permission) {
return <View />;
}
if (!permission.granted) {
return (
<View style={styles.permissionContainer}>
<Text style={{ textAlign: 'center' }}>We need your permission to show the camera</Text>
<Button title="Grant Permission" onPress={requestPermission} />
</View>
);
}
const takePicture = async () => {
setIsTakingPicture(true);
const photo = await camera.takePictureAsync( { pictureSize: '640x480', quality: 0.5 });
navigation.navigate('ImagePreview', { photo });
setIsTakingPicture(false);
};
return (
<View style={styles.container}>
<CameraView
style={styles.camera}
type='back'
flashMode='auto'
pictureSize='640x480'
ratio='640x480'
enableTorch={enableTorch}
ref={(ref) => {
camera = ref;
}}
onCameraReady={() => {
setEnableTorch(false);
}}
>
<Button title="Photo" onPress={takePicture} />
</CameraView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
camera: {
flex: 1,
},
});
the ratio
, pictureSize
, as props or as options for takePictureAsync()
don’t work wether I put ‘4/3’ or ‘640×480’.
When using getAvailablePictureSizesAsync
I get this result
0: "3840x2160"
1: "1920x1080"
2: "1280x720"
3: "640x480"
4: "352x288"
5: "Photo"
6: "High"
7: "Medium"
8: "Low"
Moreover I need to also set the same ratio for any mobile phone that will use the camera, so how can I take a size from the getAvailablePictureSizesAsync
if this might not be an option on another mobile phone?
Thank you.