【发布时间】:2021-10-03 19:03:24
【问题描述】:
我正在使用带有 react-native-image-picker 的 react native
当我加载照片时(通过使用 showCameraRoll 函数),图像尺寸太大。大小为 4032 x 3024,总图片大小超过 3MB。
但我想让大小小于 1024 * 1024 和 900KB。我该怎么办?
这是我的代码
import {launchImageLibrary} from 'react-native-image-picker';
const Upload = ({navigation}) => {
const options = {
title: 'Load Photo',
customButtons: [
{name: 'button_id_1', title: 'CustomButton 1'},
{name: 'button_id_2', title: 'CustomButton 2'},
],
storageOptions: {
skipBackup: true,
path: 'images',
},
};
const showCameraRoll = () => {
launchImageLibrary(options, (response) => {
if (response.error) {
} else {
setImageSource(response.uri);
}
const form = new FormData();
form.append('image', {
name: 'SampleFile.jpg', // Whatever your filename is
uri: response.uri, // file:///data/user/0/com.cookingrn/cache/rn_image_picker_lib_temp_5f6898ee-a8d4-48c9-b265-142efb11ec3f.jpg
type: 'image/jpg', // video/mp4 for videos..or image/png etc...
});
};
如何修复我的代码来解决这个问题?
【问题讨论】:
-
The size is 4032 x 3024你的意思是分辨率
标签: javascript android node.js reactjs react-native