在swift中使用sdwebimage获取图像原始大小

问题描述 投票:-4回答:1

我从firebase下载图像,但我不能制作原始大小的图像我该怎么办?谢谢

swift sdwebimage
1个回答
0
投票

从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!)
     }
  }
© www.soinside.com 2019 - 2024. All rights reserved.