简体   繁体   English

从android react-native + expo的手机本地存储加载图像

[英]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> ); } }

  1. Get the network address path获取网络地址路径

    1. Establish the URL object建立 URL 对象

    2. Establish the URL link conn建立 URL 链接 conn

    3. Set the link method of Conn.设置 Conn 的链接方式。

    4. Get the input stream of Conn获取Conn的输入流

    5. New a byte[]arry .新建一个byte[]arry

    6. Create a local file and get the output stream of the file.创建本地文件并获取文件的输出流。

    7. Write byte[]to file with OutputStream .使用OutputStreambyte[]to文件。

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

相关问题 在react-native android中显示来自本地存储的通知 - Show notification from local storage in react-native android React-Native:从 Firebase 存储下载图像 - React-Native: Download Image from Firebase Storage 将图像从React-Native应用程序上传到Firebase存储 - Uploading image from React-Native app to Firebase storage 如何在 React-native 中显示来自 Firebase 存储的图像? - How to display Image from Firebase storage in React-native? 无法在 expo react native 中从 url 下载图像到本地目录 - Unable to download image to local directory from url in expo react native 在 expo react-native 应用程序中初始化 firebase 电话身份验证 - Initializing firebase phone auth within expo react-native application react-native - 图像需要来自JSON的本地路径 - react-native - Image require local path from JSON Expo React Native,如何选择从 expo 图像选择器获得的默认本地图像或用户图像 - Expo React Native, How to pick default local images or user image obtained from expo image picker React Native Expo:将 Expo ImagePicker 图像保存到本地文件夹时遇到问题 - React Native Expo: Trouble Saving an Expo ImagePicker image to a local folder 使用 expo react-native 将图像上传到 firebase - Uploading image to firebase using expo react-native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM