栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

解析数组图像以保存和获取

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

解析数组图像以保存和获取

我认为您正在尝试做这样的事情。这只是一个例子。有很多工作要做,但是希望这可以帮助您入门。我没有运行或测试此代码。

想法是将图像另存为

PFFiles
,并
PFObject
为每个文件创建一个“平铺” 。然后将所有“ tile”保存
PFObject
到图像的“
tiles”键中
PFObject
。然后在需要时调用图像
objectId

祝好运。

let appleTiles = ["apple1, apple2, apple3"]let orangeTiles = ["orange1, orange2, orange3, orange4, orange5"]func usage() {    //dont literally run these synchronously like this    post(appleTiles)    post(orangeTiles)    download()}func post(_ tileNames: [String]) {    let image = PFObject(className: "Image")    let tilesPF = tileNames.map({ name in        let data = UIImagePNGRepresentation(UIImage(named: name))!        let file = PFFile(data: data)        let tile = PFObject(className: "Tile")        tile["tile"] = file    })    image["tiles"] = tilesPF    image?.saveInBackground(block: { responseObject, error in        //you'll want to save the object ID of the PFObject if you want to retrieve a specific image later    })}func download() {    let query = PFQuery(className: "image")    //add this if you have a specific image you want to get    query.whereKey("objectId", equalTo: "someObjectId")    query.findObjectsInBackground({ result, error in        //this is probably close to how you'd unwrap everything but again, I didn't test it so...        if let objects = result as? [PFObject], let first = objects.first, let image = first["image"] as? PFObject, let tiles = image["tiles"] as? [PFObject] { tiles.forEach({ tile in     let file = tile["tile"]     //now you have an individual PFFile for a tile, do something with it })        }    })}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367981.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号