繁体   English   中英

如何快速解析加载图像?

[英]How do I load an image from parse in swift?

我想知道是否有人可以帮助我,我是应用程序开发的新手,我正在从应用程序上传图像以进行解析,而解析文档的帮助没有问题。

    let imageData = UIImagePNGRepresentation(scaledImage)
    let imageFile: PFFile = PFFile(data: imageData)

    var userPhoto = PFObject(className: "postString")
    userPhoto["imageFile"] = imageFile
    userPhoto.saveInBackground()

但是当我添加代码以取回图像时,我有点迷路了:/

let userImageFile = anotherPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
  if !error {
     let image = UIImage(data:imageData)
   }
}

“ anotherPhoto”从哪里来? 解析确实说:“在这里,我们从另一个名为anotherPhoto的UserPhoto中检索图像文件:”

anotherPhoto将是您的postString的实例(在您的上载示例中为userPhoto )。 适用于您的文件下载示例如下所示:

let userImageFile = userPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
    (imageData: NSData!, error: NSError!) -> Void in
    if !error {
        let image = UIImage(data:imageData)
    }
}

任何PFFile必须从普通PFObject引用,否则无法检索。 PFFile对象本身不会显示在数据浏览器中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM