我如何将 Sqlite 中的图像显示到 uicollectionview

How can i show Images from Sqlite to a uicollectionview

我在 sqlite 数据库中有一些图像。我将 Image 保存为 BLOB 类型(我在 img.pngdata 中转换为 NSData 并将其保存到 db)。现在我想检索图像并在 uicollectionview 视图中显示它们。当我检索图像时,它就像 this 1. Which type of array should I use to show them in collection view? The table in the db is like this2.

此外,如何从检索到的图像中获取图像名称作为字符串?

我通过像这样检索 blob 数据解决了这个问题:

let lenght:Int = Int(sqlite3_column_bytes(queryStatement, 0));
let imgdata : NSData = NSData(bytes: sqlite3_column_blob(queryStatement, 0), length: lenght)
let decoded_img : UIImage = UIImage(data: imgdata as Data)!
imageNames.append(decoded_img)

我声明了一个 UIImage 类型的数组,然后在 uicollectionview 视图中使用它,它现在对我来说工作正常。