【发布时间】:2019-03-16 09:10:22
【问题描述】:
我从 firebase 下载图像,但无法制作原始大小的图像,我该怎么办?谢谢
【问题讨论】:
-
你能发布一些你到目前为止尝试过的代码吗?
-
请清楚并清楚描述您所面临的情况。
标签: swift sdwebimage
我从 firebase 下载图像,但无法制作原始大小的图像,我该怎么办?谢谢
【问题讨论】:
标签: swift sdwebimage
正如 Firebase 文档所说:
在内存中下载
使用 dataWithMaxSize:completion: 方法将文件下载到内存中的 NSData 对象。这是快速下载文件的最简单方法,但它必须将文件的全部内容加载到内存中。如果您请求的文件大于应用程序的可用内存,您的应用程序将崩溃。为防止出现内存问题,请确保将最大大小设置为您知道您的应用可以处理的大小,或使用其他下载方法。
一旦您获得了对图像路径的引用,您就可以请求下载特定文件大小的图像。来源->https://firebase.google.com/docs/storage/ios/download-files
// Create a reference to the file you want to download
let islandRef = storageRef.child("images/island.jpg")
// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
islandRef.getData(maxSize: 1 * 1024 * 1024) { data, error in
if let error = error {
// Uh-oh, an error occurred!
} else {
// Data for "images/island.jpg" is returned
let image = UIImage(data: data!)
}
}
【讨论】: