arrays - 如何在 React Native Expo 上显示字节数组图像?
问题描述
我可以byte-array
在 Swagger 上查看图像,但不能在 React Native 上查看。我已经尝试将它转换为base64
并且它可以工作,但我想知道如何将它显示在byte-array
.
- 这是我的后端端点,使用 spring-boot
@GetMapping(value = "/{id}", produces = { "image/jpg", "image/jpeg", "image/png" })
public ResponseEntity<Resource> getImage(@PathVariable final UUID id){
final User user = userService.findById(id).orElseThrow(() -> new ResourceNotFoundException("User Not Found."));
Optional<Image> image = imageService.findByUser(user);
if(image.isPresent()) {
byte[] bytes = Files.readAllBytes(Paths.get(image.get().getSignDocPath()));
return ResponseEntity.ok().body(new ByteArrayResource(bytes));
}
}
- 这就是我在 React Native 上显示图像的方式
<Image
source={{ uri: imageItem.url }}
style={styles.imagePreview}
/>
解决方案
你可以使用这个:
const getImageSource = () => {
return `data:image/jpeg;base64,${source}`
}
<Image style = {styles.image} source = {{uri: getImageSource()}}/>
推荐阅读
- unity3d - 使用 Zenject 注入带有接口的实现
- xml - 将 OR 推入节点检查
- android - Expo InAppPurchases connectAsync 返回未定义
- javascript - 当我将打字稿代码解析为 ast 时,保留关键字“private”
- javascript - :disabled 表单按钮在 Vue 3 中不起作用
- flutter - 如何在标签栏视图颤动中一次将指示器颜色设置为多个标签?
- javascript - 如何有效地将 JavaScript Json 解析为 Python dict 类型
- analytics - SPSS逻辑回归可接受方程
- python - Pandas 中的条件转换
- qb64 - QB64 中的控制中断