简体   繁体   中英

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. 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> ); } }

  1. Get the network address path

    1. Establish the URL object

    2. Establish the URL link conn

    3. Set the link method of Conn.

    4. Get the input stream of Conn

    5. New a byte[]arry .

    6. Create a local file and get the output stream of the file.

    7. Write byte[]to file with OutputStream .

    8. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM