【问题标题】:Save image from URL to device with React Native使用 React Native 将图像从 URL 保存到设备
【发布时间】:2016-04-19 17:54:39
【问题描述】:

您好,正如标题所示,我需要将图像从我的 CDN 保存到 Android 设备。

我正在使用 React Native 构建应用程序,我所做的是:

fetch('https://server.com/images.json').then((json) => console.log(json))

返回json:

{images: ["cdn.server.com/image1.jpg", "cdn.server.com/image2.jpg"]}

现在我真的不知道如何将图像保存到我的设备,因为那时我需要使用它们来打开 Instagram Intent (https://www.instagram.com/developer/mobile-sharing/android-intents/),并且它只有在图像保存到设备时才有效。

有什么想法吗?

【问题讨论】:

    标签: android react-native


    【解决方案1】:

    我不知道 React 是否可以使用 Java 代码。

    我不喜欢使用此代码从 url 获取图像。

    String imageCDN = json.getString("images");
    ImageLoader imageLoader = new ImageLoader(this);
    ImageView imgflag = (ImageView) findViewById(R.id.flag);
    
    imageLoader.DisplayImage(imageCDN, imgflag);
    

    但你应该read this tutorial 在此代码处:

    renderMovie(movie) {
    return (
      <View style={styles.container}>
        <Image
          source={{uri: movie.posters.thumbnail}}
          style={styles.thumbnail}
        />
        <View style={styles.rightContainer}>
          <Text style={styles.title}>{movie.title}</Text>
          <Text style={styles.year}>{movie.year}</Text>
        </View>
      </View>
    );
    }
    

    由于内存泄漏,您不需要保存图像,使用ListView克隆DataSource中的所有图像。

    【讨论】:

    猜你喜欢
    • 2021-09-21
    • 1970-01-01
    • 2020-06-22
    • 2015-06-19
    • 2014-03-01
    • 2018-01-09
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    相关资源
    最近更新 更多