Ios 解析图像保存问题
我不太熟悉一般的编码,已经基于apple和解析代码构建了一个照片区应用程序 尽管多次尝试调整代码,但我无法将图像保存到我的分析仪表板。你能告诉我哪里出了问题吗 我使用的代码如下:Ios 解析图像保存问题,ios,objective-c,parse-platform,Ios,Objective C,Parse Platform,我不太熟悉一般的编码,已经基于apple和解析代码构建了一个照片区应用程序 尽管多次尝试调整代码,但我无法将图像保存到我的分析仪表板。你能告诉我哪里出了问题吗 我使用的代码如下: - (IBAction)showImagePickerForPhotoPicker:(id)sender { NSLog(@"Code shows image picker for album in APLViewController.m"); [self showImagePickerForSourceType:UI
- (IBAction)showImagePickerForPhotoPicker:(id)sender
{
NSLog(@"Code shows image picker for album in APLViewController.m");
[self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *editedImage, *imageToUse;
// Handle a still image picked from a photo album
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
== kCFCompareEqualTo) {
editedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
if (editedImage) {
imageToUse = editedImage;
} else {
imageToUse = originalImage;
}
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
NSLog(@"Code reached parse save code");
NSData *imageData = UIImagePNGRepresentation (originalImage);
PFFile *imageFile = [PFFile fileWithName:@"image.png" data:imageData];
PFObject *userPhoto = [PFObject objectWithClassName:@"UserPhoto"];
userPhoto[@"imageName"] = @"My trip to Hawaii!";
userPhoto[@"imageFile"] = imageFile;
[userPhoto saveInBackground];
NSLog(@"code reaches addobject to captured images array");
[self.capturedImages addObject:image];
UIGraphicsBeginImageContext(CGSizeMake(640, 960));
[image drawInRect: CGRectMake(0, 0, 640, 960)];
谢谢我认为保存过程需要在imagePicker之外。应该是这样的。并应在一切都已完成时运行,以拾取图像
PFUser *profile = [PFUser currentUser];
NSData *imageData = UIImageJPEGRepresentation(profileImage.image, 0.8);
NSString *filename = [NSString stringWithFormat:@"%@", profile.username];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[profile setObject:imageFile forKey:@"profileimageFile"];
[profile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
// Show success message
}
else {
// Show error message
}
}];
要保存配置文件图像,您需要首先选择要保存图像的位置。在这种情况下,是在当前用户。然后将拾取的图像转换为NSData文件。然后,您需要为该数据文件命名。然后从中创建一个PFFile。然后保存该文件以进行分析
将图像恢复到原来的状态是一样的,但是是向后的:
PFFile *userImageFile = [PFUser currentUser][@"profileImageFile"];
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:imageData];
}
}];
我认为保存过程需要在imagePicker之外。应该是这样的。并应在一切都已完成时运行,以拾取图像
PFUser *profile = [PFUser currentUser];
NSData *imageData = UIImageJPEGRepresentation(profileImage.image, 0.8);
NSString *filename = [NSString stringWithFormat:@"%@", profile.username];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[profile setObject:imageFile forKey:@"profileimageFile"];
[profile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
// Show success message
}
else {
// Show error message
}
}];
要保存配置文件图像,您需要首先选择要保存图像的位置。在这种情况下,是在当前用户。然后将拾取的图像转换为NSData文件。然后,您需要为该数据文件命名。然后从中创建一个PFFile。然后保存该文件以进行分析
将图像恢复到原来的状态是一样的,但是是向后的:
PFFile *userImageFile = [PFUser currentUser][@"profileImageFile"];
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:imageData];
}
}];