0
我試圖獲取帶有文件URL(「file:///var/mobile/Media/DCIM/100APPLE/IMG_0056.JPG」)的圖像,this method很好用,但有沒有辦法讓它變得更好?因爲檢索圖像需要很長時間。直接使用文件URL返回的圖像
我曾嘗試與URL獲得直接的形象,用這種方法:
if let url = URL(string: self.path) {
print(url) (print = file:///var/mobile/Media/DCIM/100APPLE/IMG_0056.JPG)
do {
let data = try Data(contentsOf: url)
print(data)
let image2 = UIImage(data: data as Data)
return image2
} catch {
print(error.localizedDescription)
// (print = Impossible d’ouvrir le fichier « IMG_0056.JPG » car vous ne disposez pas de l’autorisation nécessaire pour l’afficher.)
// Traduction : Unable to open file "IMG_0056.JPG" because you do not have permission to view it.
}
}
return nil
我如何才能訪問到該圖像直接?