gpt4 book ai didi

IOS Swift 使用 URL 加载(本地)图像

转载 作者:行者123 更新时间:2023-11-30 13:33:50 28 4
gpt4 key购买 nike

我们可以使用 URL 选项通过 SDWebimage 加载在设备本地找到的图像吗?如果是,那么我尝试使用 SDWebimage 来显示图像,下面是我的代码,我无法在 imageview 中加载图像。它仍然是空白的。请帮助我了解我做错了什么?

func addImage(sender: AnyObject){

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum){

picController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
picController.allowsEditing = true
self.presentViewController(picController, animated: true, completion: nil)
}
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let url = info[UIImagePickerControllerReferenceURL] as! NSURL
titleImageView.sd_setImageWithURL(url)

self.dismissViewControllerAnimated(true, completion: nil)

}

最佳答案

请注意 UIImagePickerController 委托(delegate)imagePickerController:didFinishPickingMediaWithInfo

将具有文档中描述的信息-

A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked. The dictionary also contains any relevant editing information. The keys for this dictionary are listed in Editing Information Keys.

因此,如果您正在查看的是图像,它将就在字典本身中。

您可以直接获取原始图像-

let image = info[UIImagePickerControllerOriginalImage]

if let image = image {
//Set this image to your image view directly
titleImageView.image = image
}

关于IOS Swift 使用 URL 加载(本地)图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36306559/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com