解析数组图像保存和获取 [英] Parse array images saving and fetching

查看:84
本文介绍了解析数组图像保存和获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个马赛克应用程序,可以拍摄多张照片并将它们分成更小的照片。根据照片的大小,较小的照片数量可能会有所不同。现在我有一个名为 imageNameList2 NSMutableArray ,其中包含从较大图像中获取的所有较小图像。在这个例子中,我展示了一个示例,其中从图像资源列表中调用图像,以便更容易回答这个问题。

I have a mosaic app that takes multiple size photos and breaks them into smaller photos. Depending on the size of the photo, the amount of smaller photos could vary. Now I have an NSMutableArray named imageNameList2 that holds all of the smaller images taken from the larger image. For this example I showed an example with the images being called from the image assets list to make it easier to answer this question.

这是 imageNameList NSMutableArray ,它包含所有较小的图片)

Here is the imageNameList (NSMutableArray that holds all the smaller images)

var imageNameList: [String] {
    var imageNameList2:[String] = [] //[NSMutableArray]()
    for i in 0...149 {
        let imageName = String(format: "pic_%03d", Int(i))
        imageNameList2.append(imageName)
    }
    return imageNameList2
}

我想要什么要做的是有一个继续按钮,将按顺序保存所有这些图像,因为piffles或任何其他格式解析效果最好,并有另一个名为retrieve的按钮,将从解析中检索所有这些照片。我基本上有一个解析服务器,它利用解析框架来帮助加速后端进程。如果每次存储的图像数量不同,你能告诉我如何保存和检索这个 NSMutableArray 吗?

What I'd like to do is have a continue button that will save all these images in order as piffles or any other format to parse that works best and have another button called retrieve that will retrieve all these photos from parse. I basically have a parse server that utilizes parse frameworks to help speed up the backend process. Can you please show me how I would save and retrieve this NSMutableArray if there are different numbers of stored images each time?

推荐答案

我想你正试图做这样的事情。这只是一个例子。还有很多工作要做,但希望这会让你开始。我没有运行或测试此代码。

I think you're trying to do something like this. This is just an example. There's a lot of work to be done but hopefully this will get you started. I did not run or test this code.

我们的想法是将您的图像保存为 PFFiles ,并创建一个每个文件的'tile' PFObject 。然后将所有'tile' PFObject 保存到图像 PFObject 的'tiles'键。然后通过 objectId 调用图像。

The idea is to save your images as PFFiles, and create a 'tile' PFObject for each file. Then save all the 'tile' PFObjects to a 'tiles' key of the image PFObject. Then recall the image when you need it by 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
            })
        }
    })
}

这篇关于解析数组图像保存和获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆