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


- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01