My code does not gives any error when executed over expo (react-native) but the image is also not loading. 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/". But this too does not work. The only output I get is the Hello, world! text.My device is Huawei 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
Establish the URL link conn
Set the link method of Conn.
Get the input stream of Conn
New a byte[]arry
.
Create a local file and get the output stream of the file.
Write byte[]to
file with OutputStream
.
Then bitmapfactory.decodefile ()
, get the bitmap object and display it on the picture control.
为源道具 Ex 设置宽度和高度:
<Image source={{width:200,height:200,uri:'file:///storage/emulated/0/DCIM/images.jpeg'}}/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.