我想将图像从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
答案 0 :(得分:5)
创建一个swift类文件,我在链接中给你,并用下面的行调用该类。
// 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>