javascript - 将图像 uri 转换为 Base64
问题描述
我使用下面的代码上传带有相机和画廊的图像。我想将其编码为 Base64 以离线保存。我看不到方法,如何修改我的代码以在 Base64 中转换 Image uri。
import PhotoUpload from 'react-native-photo-upload'
const [ image, setImage ] = useState( false )
//const [agree, setAgree] = useState(false);
const [ teacherNameActive, setTeachersNameActive ] = useState( false )
return (
<>
<LinearGradient
colors={ [ '#FFFF', '#FFFF' ] }
style={ styles.linearGradient }>
<Text style={ styles.ScreenTitle }>Registration</Text>
<ScrollView>
<View style={ {
alignSelf: 'center',
backgroundColor: '#90C9C6',
width: 120,
height: 120,
borderRadius: 75
} }>
<PhotoUpload onPhotoSelect={ Avatar => {
if ( Avatar ) {
console.warn( 'Image string:', Avatar )
setImage( true )
}
} }
>
{ image ?
<Image
style={ styles.upload_Image_style }
/> : <>
<Image style={ styles.camera_image }
source={ require( "../../assets/profileIcons/Combined_Shape.png" ) }
//source={ imageSource }
/>
<Text style={ styles.camera_text }>Upload</Text>
<Text style={ styles.camera_text }>Photo</Text>
</>
}
</PhotoUpload>
</View>
解决方案
推荐阅读
- javascript - 错误连接拒绝来自另一台设备的 localhost:5000/user
- javascript - 将单列放在数据表/yajra 数据表中多个父列的子行中
- r - 使用melt将数据合并到一个长列中
- oracle - 触发器不编译
- excel - “3706”:尝试通过 VBA 连接到 SQL SERVER 时找不到提供程序
- reactjs - reactjs错误-TypeError:无法读取未定义的属性“地图”
- python - Numpy:检索过滤数组中原始列的最有效方法
- jestjs - 手动 Jest 模拟不适用于 create-react-app
- typescript - Vue 类型脚本 - 数据和自定义类型
- android - Android studio Kotlin 多个按钮打开多个activity