【问题标题】:React-Native Image tag defaultSource point to in memory image data?React-Native Image标签defaultSource指向内存中的图像数据?
【发布时间】:2018-07-17 17:01:05
【问题描述】:

文档说:

defaultSource

A static image to display while loading the image source.

    uri - a string representing the resource identifier for the image, which should be either a local file path or the name of a static image resource (which should be wrapped in the require('./path/to/image.png') function).
    width, height - can be specified if known at build time, in which case these will be used to set the default <Image/> component dimensions.
    scale - used to indicate the scale factor of the image. Defaults to 1.0 if unspecified, meaning that one image pixel equates to one display point / DIP.
    number - Opaque type returned by something like require('./image.jpg').

仅供参考。如何引用内存中的图像数据,例如来自https://www.npmjs.com/package/react-native-fetch-blob#download-example--fetch-files-that-needs-authorization-token的示例代码

RNFetchBlob.fetch('GET', 'http://www.example.com/images/img1.png', {
    Authorization : 'Bearer access-token...',
    // more headers  .. 
  })
  // when response status code is 200 
  .then((res) => {
    // the conversion is done in native code 
    let base64Str = res.base64()
    // the following conversions are done in js, it's SYNC 
    let text = res.text()
    let json = res.json()

  })
  // Status code is not 200 
  .catch((errorMessage, statusCode) => {
    // error handling 
  })

【问题讨论】:

标签: android react-native


【解决方案1】:

我认为这是不可能的。

defaultSource 属性只接受两种不同的类型:

  1. 一个数字,由require('./image.jpg')返回
  2. 具有此形状的对象:{uri: string, width: number, height: number, scale: number}uri 字段是一个字符串,用于指向来自本机端的图像。

【讨论】:

    猜你喜欢
    • 2023-02-11
    • 2019-07-07
    • 2022-08-19
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    • 2017-07-21
    • 1970-01-01
    相关资源
    最近更新 更多