【问题标题】:How to convert bytes into a UIImage in Swift?如何在 Swift 中将字节转换为 UIImage?
【发布时间】:2019-12-01 00:28:44
【问题描述】:

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

iVBORw0kGg...

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

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

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

【问题讨论】:

标签: swift uiimage uikit


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    • 2019-10-20
    • 2017-01-06
    • 2013-06-11
    相关资源
    最近更新 更多