反应本机< Image>无法从android中的sdcard加载图像 [英] React Native <Image> not loading image from sdcard in android

查看:188
本文介绍了反应本机< Image>无法从android中的sdcard加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从React本地图像组件中的相机拍照后,尝试从外部sdcard加载图像,如下所示,但它无法在android中渲染.我什至检查了该位置是否有图像丢失,但这不是问题所在.但是,在iOS上从相机拍照后从位置加载图像的情况下,效果很好.

I am trying to load image from external sdcard after I take photo from camera in React native image component as following, but it is not rendering in android. I even checked if there is image missing at that location, but that's not the problem. But it works well in case of iOS to load image from location after taking photo from camera.

 <Image source={{uri:'/storage/emulated/0/Pictures/image-0ea0d714-9469-432b-8869-b6637be2be10.jpg'}} style={{height:200, width:200}} />

这是我在 AndroidManifest.xml

<!-- For Image picker start -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>

推荐答案

只有这个问题,通过在文件路径前添加 file://

Just had this issue, solved it by prepending the filepaths with file://

所以,而不是:

 <Image source={{uri:'/storage/emulated/0/Pictures/myImage.jpg'}} style={myImageStyle} />

使用:

 <Image source={{uri:'file:///storage/emulated/0/Pictures/myImage.jpg'}} style={myImageStyle} />

请注意三个连续的斜杠,而不是@Cherniv建议的两个斜杠.

Note the 3 consecutive slashes as opposed to just two as suggested by @Cherniv.

这篇关于反应本机&lt; Image&gt;无法从android中的sdcard加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆