gpt4 book ai didi

ios - 如何将选中的图片转换为字符串进行存储?

转载 作者:行者123 更新时间:2023-11-28 06:28:38 25 4
gpt4 key购买 nike

我在 Assets.xcassets 中有名为 city_00,city_01,...,city_10 的图像

我将它们存储在一个数组中

 let cityImages: [UIImage] = [UIImage(named: "city_00")!,UIImage(named: "city_01")!,.....UIImage(named: "city_10")!]

然后我在我的项目中使用 collectionview 调用它们并允许用户选择他们喜欢的任何城市

 var imageSelected = [UIImage]()
var cityImage:UIImage?

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
collectionView.allowsMultipleSelection = false
cityImage = imageSelected[(indexPath as NSIndexPath).row]
}

我喜欢通过将所选图像转换回字符串来将它们保存在数据库中。我该怎么做?

最佳答案

let cityImageData = UIImagePNGRepresentation(cityImage)
let imageString = cityImageData?.base64EncodedString()

关于ios - 如何将选中的图片转换为字符串进行存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41038041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com