【问题标题】:Saving an Image using Parse SDK使用 Parse SDK 保存图像
【发布时间】:2014-05-22 05:35:49
【问题描述】:

拍照:

我正在使用此问题中的代码拍摄图像: Scaling UIImage with a UIIImagePicker's CGAffineTransform and Saving to Parse SDK

将 UIImage 转换为 NSData 并保存

    _imageData = UIImageJPEGRepresentation(_image, .1);
    PFFile *imageFile = [PFFile fileWithName:@"image.png" data:_imageData];
    newMessage[@"image"] = imageFile;

问题:

当我重新下载数据时,UIImage 似乎被压扁了。当我查看数据库中的图像时,似乎高度和宽度颠倒了。不知道为什么会这样……

【问题讨论】:

  • 你有什么问题?
  • @InderKumarRathore 已编辑

标签: ios objective-c uiimage


【解决方案1】:
NSData *imageData = UIImageJPEGRepresentation(yourImage, 1.0);
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:imageData];

    PFObject *userPhoto = [PFObject objectWithClassName:@"Photo"];
    [userPhoto setObject:imageFile forKey:@"image"];

    // Set the access control list to current user for security purposes
    userPhoto.ACL = [PFACL ACLWithUser:[PFUser currentUser]];

    [userPhoto setObject:user forKey:@"user"];

    [userPhoto saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (!error) {
            NSLog(@"sucess");
        }
        else{
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        [[ConnectionManager sharedManager] removeload];
    }];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 2014-07-09
    • 1970-01-01
    • 2022-07-19
    相关资源
    最近更新 更多