我使用反应原生图像选择器和图像缩放器来挑选然后调整图像大小。如何在调整图像大小后获取图像的base64?
ImagePickerManager.showImagePicker(imagepicker_options, (response) => {
ImageResizer.createResizedImage(response.uri, 550, null, 'JPEG', 100).then((resizedImageUri) => {
//get base64 of image
});
});
答案 0 :(得分:4)
https://libraries.io/npm/react-native-asset-library-to-base64
ImagePickerManager.showImagePicker(imagepicker_options, (response) => {
ImageResizer.createResizedImage(response.uri, 550, null, 'JPEG', 100).then((resizedImageUri) => {
//get base64 of image, uri is link to asset-library://
ReadImageData.readImage(uri, (imageBase64) => {
console.log(imageBase64);
});
});
});
,也可能需要阅读此内容
答案 1 :(得分:0)
实际上,imagepicker_options
提供了一种调整大小的方法。
您可以在选项上传递maxWidth
和maxHeight
。
代码:
const imagepicker_options = {
mediaType: 'photo',
maxWidth: 550,
storageOptions: {
skipBackup: true,
cameraRoll: false,
path: 'images',
},
}
ImagePickerManager.showImagePicker(imagepicker_options, (response) => {
//get base64 of image
const base64 = response.data
});