【问题标题】:How can I convert image uri (not url) to base 64 in JavaScript如何在 JavaScript 中将图像 uri(不是 url)转换为 base 64
【发布时间】:2022-01-12 16:34:17
【问题描述】:

我正在尝试为机器学习分类图像创建一个带有 react native 和 expo 的移动应用程序。我的应用程序从相机拍摄照片并将 PhotoUri 发送到返回预测的函数。如何将图像 uri 转换为 base 64 字符串?

【问题讨论】:

    标签: javascript react-native base64 expo


    【解决方案1】:

    最简单的方法是使用官方的expo-image-picker。该软件包提供通过相机捕获图像或从媒体库加载图像的选项

    import * as ImagePicker from 'expo-image-picker'
    
      const pickImage = async () => {
        // No permissions request is necessary for launching the image library
        let result = await ImagePicker.launchCameraAsync({
          mediaTypes: ImagePicker.MediaTypeOptions.All,
          allowsEditing: true,
          aspect: [4, 3],
          quality: 1,
          base64:true // Return base64 image data
        });
    
        console.log(result);
    
        if (!result.cancelled) {
          //
        }
      }
    
    

    【讨论】:

      猜你喜欢
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 2020-11-27
      • 2018-03-23
      相关资源
      最近更新 更多