0
A
回答
0
试试这个: -
let documentsDirectoryURL = try! FileManager().url(for:
.documentDirectory, in: .userDomainMask, appropriateFor: nil, create:
true)
// create a name for your image
let fileURL =
documentsDirectoryURL.appendingPathComponent("imgName.png")
if !FileManager.default.fileExists(atPath: fileURL.path) {
do {
try UIImagePNGRepresentation(cahedimage!)!.write(to: fileURL)
print("Image Added Successfully")
} catch {
print(error)
}
} else {
print("Image Not Added")
}
+0
完成处理程序完成此代码将保存到文档目录。我的问题不是这样。 – AKNinan
0
加载图像中使用下面的代码图像视图。完成处理程序将帮助完成下载图像后的任何任务。
loadImage(fromUrl: URL(string: imageUrl)!, imageView: imgView, fileName: image.png)
func loadImage(fromUrl: URL, imageView: UIImageView, fileName: String) {
imageView.kf.indicatorType = .activity
imageView.kf.setImage(with:fromUrl, placeholder: nil, options: [.transition(.none)], progressBlock: nil, completionHandler: {(result) in
let documentsDirectoryURL = try! FileManager().url(for:
.documentDirectory, in: .userDomainMask, appropriateFor: nil, create:
true)
let fileURL =
documentsDirectoryURL.appendingPathComponent(fileName)
if !FileManager.default.fileExists(atPath: fileURL.path) {
do {
try UIImagePNGRepresentation(imageView.image!)!.write(to: fileURL)
print("Image Added Successfully")
} catch {
print(error)
}
} else {
print("Image Not Added")
}
})
}
相关问题
- 1. 翠鸟框架不下载图像
- 2. 翠鸟多个并行图像下载
- 3. 文档目录保存图像
- 4. 影像保存到文档目录
- 5. 将图像保存到文档目录中
- 6. 翠鸟图像调整从url加载的图像
- 7. 下载PDF,保存到文档目录并将其加载到UIWebView中
- 8. 将NSMutableDictionary保存到文档目录
- 9. 下载EPUB图书编程和文档目录保存在Xcode
- 10. 将摄像头捕获的图像保存到ios的文档目录中
- 11. 蟒蛇下载图像不会保存到正确的目录
- 12. 保存下载图像到文件
- 13. 图像不会保存到文档目录
- 14. 将文档子目录中的图像加载到UICollectionViewCell中
- 15. iOS将图像保存到文档目录放慢应用程序
- 16. UIImage保存到文档目录的内存使用率低
- 17. 如何保存捕获的图像中的文档目录
- 18. 翠鸟Firebase存储缓慢显示图像 - 迅速3
- 19. 无法使用imagepng将图像保存到所需目录()
- 20. 使用非本地路径将图像保存到目录
- 21. 使用Automator/Applescript将图像下载到特定目录
- 22. ObjC下载文件并将其保存到目录
- 23. 保存NSMutableArray到iPhone文档目录
- 24. 下载的图像在文档目录中有零字节
- 25. 下载保存在目录下自动文件中使用AIR
- 26. 如何只加载文档目录中最新保存的图像?
- 27. 将下载的曲目保存到SDCard?
- 28. 调整图像大小并将图像保存到新目录
- 29. Cordova将图像下载保存到www文件夹中
- 30. 将图像文件保存到临时目录
是的这是可能的,你到目前为止尝试过什么?什么不工作? – Scriptable
我已经通过使用与kf.setImage() – AKNinan