How to upload an image to Parse.com from UIImageView(如何从 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 UIImageView 将图像上传到 Parse.com


基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01