反应本机图像不渲染本地源

时间:2019-03-08 03:29:11

标签: ios react-native

// write image to local path
  NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES).firstObject;
  NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"a.jpg"]];
  [UIImagePNGRepresentation(image)writeToFile:filePath atomically:YES]

// under iOS (it works great)
[UIImage imageWithContentsOfFile: filePath];

// under react native (Could not find image filePath)
<Image source={{ uri:  filePath }} />

这是结果 no image

有人遇到同样的问题吗?


我试了一下,但是不好!

<Image style={{width:100, height:100}} source={{ uri: 'file://' + RNFS.DocumentDirectoryPath + '/myAwesomeSubDir/my.png', scale:1}} /> 

我知道为什么Image无法渲染源,因为源路径没有扩展名! Image doesn't render local source (path with no extension name)

0 个答案:

没有答案