如何从 UIImageView 将图像上传到 Parse.com [英] How to upload an image to Parse.com from UIImageView

查看:18
本文介绍了如何从 UIImageView 将图像上传到 Parse.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用名为Draw Me"并使用 Parse.com.用户在 UIImageView 中绘制图像,应将其保存(上传)到 Parse.com.有人可以建议怎么做吗?

My App is called "Draw Me" and use Parse.com. User draws an image in UIImageView and it should be saved(uploaded) to Parse.com. Can someone advise how to do it?

推荐答案

Parse 有一个关于这个确切主题的 iOS 教程:https://parse.com/tutorials/anypic

Parse has an iOS tutorial on this exact topic: https://parse.com/tutorials/anypic

Christian 已经概述了如何保存图像本身,但我假设您也希望将其与 PFObject 关联.基于他的答案(以保存为 jpeg 的示例)

Christian has outlined how to save the image itself, but I assume you also want to associate it with a PFObject as well. Building on his answer (with an example of saving out as jpeg)

// Convert to JPEG with 50% quality
NSData* data = UIImageJPEGRepresentation(imageView.image, 0.5f);
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:data];

// Save the image to Parse

[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        // The image has now been uploaded to Parse. Associate it with a new object 
        PFObject* newPhotoObject = [PFObject objectWithClassName:@"PhotoObject"];
        [newPhotoObject setObject:imageFile forKey:@"image"];

        [newPhotoObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (!error) {
                NSLog(@"Saved");
            }
            else{
                // Error
                NSLog(@"Error: %@ %@", error, [error userInfo]);
            }
        }];
    }
}];

这篇关于如何从 UIImageView 将图像上传到 Parse.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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