swift - 如何在 Swift 中将字节转换为 UIImage?
问题描述
我正在从我的 Firebase 数据库中读取字节信息。在 Firebase 上,图像显示为
iVBORw0kGg...
但是当我在 Xcode 中阅读它时,它显示为
ffd8ffe0 00104a46 49460001 01000001 00010000 ffdb0043 00030202 02020203 02020203 03030304 06040404 04040806 06050609 080a0a09 0809090a 0c0f0c0a 0b0e0b09...
我不确定这是什么类型的数据以及如何将其转换为 UIImage
解决方案
假设您将字节存储在一个Data
类型中,您可以直接使用 UIImage 的初始化程序。
var imageData: Data // let's assume that imageData has all the the bytes already
var image = UIImage(data: imageData)
推荐阅读
- eclipse - eclipse中黄瓜测试的初始化错误
- java - 一次只允许一个用户访问数据
- python - 用 pip 安装 wxPython (Python2.7)
- python - 将 Pandas 系列(基于索引)切片成多列数据框
- c++ - libpqxx 和 cmake 找不到 -lpq
- java - oracle keep_first 单元测试
- sql-server - SQL Server 超时未锁定
- php - 如果图像无效,检查图像是否存在需要很长时间
- r - Use viridis and Map values to colour in a histogram plot
- python - python 3:函数内输入的名称错误