如何在React Native中上传自定义尺寸的图像,使用expo-image-picker库? &g



下面是我已经编写的代码,它要求您将从相机胶卷中选择的任何图像裁剪为正方形。我想用不同的维度。

import React, { useState, useEffect } from 'react';
import { Button, Image, View, Platform } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
export default function ImagePickerExample() {
const [image, setImage] = useState(null);
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
console.log(result);
if (!result.cancelled) {
setImage(result.uri);
}
};
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button title="Pick an image from camera roll" onPress={pickImage} />
{image && <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
</View>
);
}

你可以这样做

在expo图像选择器库中,您可以更改宽高比(宽高比)来更改。选择后的图像尺寸。

你需要做的是从你的pickImage()函数中删除aspect,然后你就可以在任何尺寸上裁剪了。

这里你已经给出了aspect:[4,3],所以这是图像的尺寸,你可以删除它。

最新更新