首页 > 解决方案 > 如何在 Swift 中将字节转换为 UIImage?

问题描述

我正在从我的 Firebase 数据库中读取字节信息。在 Firebase 上,图像显示为

iVBORw0kGg...

但是当我在 Xcode 中阅读它时,它显示为

ffd8ffe0 00104a46 49460001 01000001 00010000 ffdb0043 00030202 02020203 02020203 03030304 06040404 04040806 06050609 080a0a09 0809090a 0c0f0c0a 0b0e0b09...

我不确定这是什么类型的数据以及如何将其转换为 UIImage

标签: swiftuiimageuikit

解决方案


假设您将字节存储在一个Data类型中,您可以直接使用 UIImage 的初始化程序。

var imageData: Data // let's assume that imageData has all the the bytes already
var image = UIImage(data: imageData)

推荐阅读