我想将图像从imageview保存到特定文件夹图像来自Sqlserver。我想将其链接保存在sqlite中以进行进一步处理,我已经编写了此代码,该代码将图像保存在文档目录中,但是每次路径都不相同。请告诉我应该怎么做 ?
let imageData = UIImagePNGRepresentation(imageee.image!)!
let docDir = try! FileManager.default.url(for: .picturesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let imageURL = docDir.appendingPathComponent("tmp.png")
try! imageData.write(to: imageURL)
print(imageURL.path)
let newImage = UIImage(contentsOfFile: imageURL.path)!
//aftersave.image = newImage
aftersave.image = newImage
创建一个我在链接中为您提供的快捷类文件,然后在下面的行中调用该类。
// orignal_image was UIImageView
CustomPhotoAlbum.sharedInstance.save(image: orignal_image)
您要做的最重要的事情是在info.plist文件中添加此行
<key>NSPhotoLibraryUsageDescription</key>
<string>YOUR APP need access to your camera roll and photo library</string>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句