[英]Load image from phone local storage of android react-native + expo
My code does not gives any error when executed over expo (react-native) but the image is also not loading.我的代码在expo (react-native) 上执行时没有出现任何错误,但图像也没有加载。 The path I get from details of the image in android is "Internal storage/DCIM/images.jpeg" therefore searching over forums read a suggestion to replace Internal storage with "file:///storage/emulated/0/".我从 android 中图像的详细信息获得的路径是“内部存储/DCIM/images.jpeg”,因此在论坛上搜索阅读了将内部存储替换为“file:///storage/emulated/0/”的建议。 But this too does not work.但这也行不通。 The only output I get is the Hello, world!我得到的唯一输出是Hello, world! text.My device is Huawei BG2-U01. text.我的设备是华为BG2-U01。
Hope I am not missing out on any basics.希望我不会错过任何基础知识。
import React, { Component } from 'react'; import { Text, View,Image } from 'react-native'; export default class HelloWorldApp extends Component { render() { return ( <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}> <Text>Hello, world!</Text> <Image source={{uri:'file:///storage/emulated/0/DCIM/images.jpeg'}} style={{width: 60, height: 60}} /> </View> ); } }
Get the network address path获取网络地址路径
Establish the URL object建立 URL 对象
Establish the URL link conn建立 URL 链接 conn
Set the link method of Conn.设置 Conn 的链接方式。
Get the input stream of Conn获取Conn的输入流
New a byte[]arry
.新建一个byte[]arry
。
Create a local file and get the output stream of the file.创建本地文件并获取文件的输出流。
Write byte[]to
file with OutputStream
.使用OutputStream
将byte[]to
文件。
Then bitmapfactory.decodefile ()
, get the bitmap object and display it on the picture control.然后bitmapfactory.decodefile ()
,获取位图对象并显示在图片控件上。
为源道具 Ex 设置宽度和高度:
<Image source={{width:200,height:200,uri:'file:///storage/emulated/0/DCIM/images.jpeg'}}/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.