【问题标题】:Load image from phone local storage of android react-native + expo从android react-native + expo的手机本地存储加载图像
【发布时间】:2020-01-19 10:30:16
【问题描述】:

我的代码在 expo (react-native) 上执行时没有给出任何错误,但图像也没有加载。我从 android 中图像的详细信息中获得的路径是“内部存储/DCIM/images.jpeg”,因此在论坛上搜索会看到一个建议,用“file:///storage/emulated/0/”替换内部存储。但这也行不通。我得到的唯一输出是 Hello, world! 文本。我的设备是华为 BG2-U01。

希望我不会错过任何基础知识。

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

【问题讨论】:

    标签: javascript android react-native expo huawei-mobile-services


    【解决方案1】:
    1. 获取网络地址路径

      1. 建立 URL 对象

      2. 建立 URL 链接连接

      3. 设置Conn的链接方式

      4. 获取Conn的输入流

      5. 新建一个byte[]arry

      6. 创建本地文件并获取文件的输出流。

      7. OutputStream 写入byte[]to 文件。

      8. 然后bitmapfactory.decodefile (),获取位图对象并显示在图片控件上。

    【讨论】:

      【解决方案2】:

      为源道具设置宽度和高度 例如:

      <Image source={{width:200,height:200,uri:'file:///storage/emulated/0/DCIM/images.jpeg'}}/> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-18
        相关资源
        最近更新 更多